Created
May 15, 2011 16:50
-
-
Save anonymous/973297 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup() { | |
// initialize serial communication: | |
Serial.begin(9600); | |
// initialize the LED pins: | |
for (int thisPin = 2; thisPin < 7; thisPin++) { | |
pinMode(thisPin, OUTPUT); | |
} | |
} | |
void loop() { | |
// read the sensor: | |
if (Serial.available() > 0) { | |
int inByte = Serial.read(); | |
// do something different depending on the character received. | |
// The switch statement expects single number values for each case; | |
// in this exmaple, though, you're using single quotes to tell | |
// the controller to get the ASCII value for the character. For | |
// example 'a' = 97, 'b' = 98, and so forth: | |
switch (inByte) { | |
case 'w': | |
digitalWrite(2, HIGH); | |
Serial.print("DEBUG: Powered up pin"); | |
break; | |
case 'a': | |
digitalWrite(3, HIGH); | |
Serial.print("DEBUG: Powered left pin"); | |
break; | |
case 'q': | |
digitalWrite(4, HIGH); | |
Serial.print("DEBUG: Powered button pin"); | |
break; | |
case 's': | |
digitalWrite(5, HIGH); | |
Serial.print("DEBUG: Powered down pin"); | |
break; | |
case 'd': | |
digitalWrite(6, HIGH); | |
Serial.print("DEBUG: Powered right pin"); | |
break; | |
default: | |
// turn all the LEDs off: | |
for (int thisPin = 2; thisPin < 7; thisPin++) { | |
digitalWrite(thisPin, LOW); | |
Serial.print("DEBUG: Turned pins off"); | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment