// Wiring/Arduino code:
// Read data from the serial and turn ON or OFF a light depending on the value
char val; // Data received from the serial port
int ledPin8 = 8; // Set the pin to digital I/O 8
int ledPin9 = 9; // Set the pin to digital I/O 9
int ledPin10 = 10; // Set the pin to digital I/O 10
void setup() {
pinMode(ledPin8, OUTPUT); // Set pin as OUTPUT
pinMode(ledPin9, OUTPUT); // Set pin as OUTPUT
pinMode(ledPin10, OUTPUT); // Set pin as OUTPUT
Serial.begin(9600); // Start serial communication at 9600 bps
}
void loop() {
if (Serial.available()>0) { // If data is available to read,
val = Serial.read(); // read it and store it in val
}
if (val == 'A') { // If 'A' was received from Processing code
digitalWrite(ledPin8, HIGH); // turn the LED on
}
if (val == 'B') { // If 'B' was received from Processing code
digitalWrite(ledPin8, LOW); // Turn the LED off
}
if (val == 'C') { // If 'C' was received from Processing code
digitalWrite(ledPin9, HIGH); // turn the LED on
}
if (val == 'D') { // If 'D' was received from Processing code
digitalWrite(ledPin9, LOW); // Turn the LED off
}
if (val =='E') { // If 'E' was received from Processing code
digitalWrite(ledPin10, HIGH); // turn the LED on
}
if (val =='F') {
digitalWrite(ledPin10, LOW); // Turn the LED off
}
//delay(10); // Wait 100 milliseconds for next reading
}