title: Control an Arduino with Java
body: <p>I am looking to turn an <a href="http://en.wikipedia.org/wiki/Light-emitting_diode" rel="noreferrer">LED</a> on and off with a Java program. I did the project in C# in roughly 5 minutes, but it seems to be somewhat more challenging in Java. I had the Arduino wait for a 1 or 0 to be written to the <a href="http://en.wikipedia.org/wiki/COM_%28hardware_interface%29" rel="noreferrer">COM port</a> and would change the LED based on that. The code I am using for the Arduino is as follows.</p>
  
  <pre><code>int LedPin = 13;
  char data;
  
  void setup()
  {
      Serial.begin(9600);
      pinMode( LedPin , OUTPUT );
  }
  
  void loop()
  {
      data = Serial.read();
      if (Serial.available() &gt; 0)
      {
          if(data == '1' )
          {
              digitalWrite(LedPin,HIGH);
          }
          else if(data == '0' )
          {
              digitalWrite(LedPin,LOW);
          }
      }
      else
          if (Serial.available()&lt;0)
          {
              digitalWrite(LedPin,HIGH);
              delay(500);
              digitalWrite(LedPin,LOW);
              delay(500);
          }
  }
  </code></pre>
  
  <p>How would I do this with a Java application?</p>