This example is for Wiring version 0023+. If you have a previous version, use the examples included with your software. If you see any errors or have comments, please let us know.
Simple Read
Read data from the serial port and turn ON the onboard LED if the character received is an 'a'
Read data from the serial port and turn ON the onboard LED if the character received is an 'a'
int val; // to read the char
int ledPin = 48; // onboard led pin
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop() {
if(Serial.available()) { // if data available
val = Serial.read(); // read data
if(val == 'a') { // if value read is character 'a'
digitalWrite(ledPin, HIGH); // turn ON the onboard LED
} else {
digitalWrite(ledPin, LOW); // if not turn it OFF
}
}
delay(100); // wait 100ms for next read
}

