Arduino Tutorial: Use PC to Blink an LED

/* Blinking LED (This code is for Arduino!)
* ------------
*
* turns on and off a light emitting diode(LED) connected to a digital
* pin, based on data coming over serial
*/

int ledPin = 13; // LED connected to digital pin 13
int inByte = 0;

void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
Serial.begin(19200); // initiate serial communication
}

void loop()
{
while (Serial.available()>0) {
inByte = Serial.read();
}
if (inByte>0) {
digitalWrite(ledPin, HIGH); // sets the LED on
} else {
digitalWrite(ledPin, LOW); // sets the LED off
}
}

Categories: | | |