Loading ...
Sorry, an error occurred while loading the content.

426Requesting some Help On the Digital Output

Expand Messages
  • jujames84
    Jun 10, 2010
    • 0 Attachment
      I wrote this program that takes an input from the Analog Input (A01) - Hight or Low and then determines what to do next based on an output to the Digital Input 1 (IO1). Now that works fine - Sample Code:

      [code]
      import com.ridgesoft.intellibrain.IntelliBrain;
      import com.ridgesoft.intellibrain.IntelliBrainAnalogInput;
      import com.ridgesoft.intellibrain.IntelliBrainDigitalIO;
      import java.io.OutputStream;
      import java.io.InputStream;
      import javax.comm.SerialPort;

      public class Main
      {

      /**
      * @param args the command line arguments
      */
      public static void main(String[] args)
      {
      // TODO code application logic here
      try
      {
      IntelliBrainAnalogInput switch1 = IntelliBrain.getAnalogInput(1);
      IntelliBrainDigitalIO led1 = IntelliBrain.getDigitalIO(1);
      led1.setDirection(true);

      while(true /*(data = inStream.read()) != -1*/)
      {
      // Switch1 and LED1
      if(switch1.isSet() == true)
      {
      led1.set();
      // test if it is working
      System.out.println("Switch 1 is ON");
      }
      else
      {
      led1.clear();
      //outStream.write(1);
      System.out.println("Switch 1 is OFF");
      }

      }
      }
      catch(Exception error)
      {
      error.printStackTrace();
      }
      }

      }

      [/code]

      Ok I modify the code to out the information while reading if there is any information at the same time throught the COM Port 1. But when I do that, the intellibrain is no longer responding through RoboJDE. The real problem is the output is no longer working, because I set up a LED Circuit to test the output and it did work before I added the output.write() COM Port.... Heres my sample:


      [code]
      import com.ridgesoft.intellibrain.IntelliBrain;
      import com.ridgesoft.intellibrain.IntelliBrainAnalogInput;
      import com.ridgesoft.intellibrain.IntelliBrainDigitalIO;
      import java.io.OutputStream;
      import java.io.InputStream;
      import javax.comm.SerialPort;

      public class Main
      {

      /**
      * @param args the command line arguments
      */
      public static void main(String[] args)
      {
      // TODO code application logic here
      try
      {
      IntelliBrainAnalogInput switch1 = IntelliBrain.getAnalogInput(1);
      IntelliBrainDigitalIO led1 = IntelliBrain.getDigitalIO(1);
      led1.setDirection(true);

      SerialPort comPort = IntelliBrain.getCom1();
      InputStream inStream = comPort.getInputStream();
      OutputStream outStream = comPort.getOutputStream();
      int data;

      while((data = inStream.read()) != -1)
      {
      // Switch1 and LED1
      if(switch1.isSet() == true && (data = inStream.read()) != 21)
      {
      led1.set();
      outStream.write(0);
      }
      else
      {
      led1.clear();
      outStream.write(1);
      }

      }
      }
      catch(Exception error)
      {
      error.printStackTrace();
      }
      }

      }

      [/code]

      I tried to account for the input data, but as I said the Digital output stopped working (using the LED Circuit Test)
    • Show all 3 messages in this topic