Created
July 3, 2009 23:16
-
-
Save geekscape/140366 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
byte pinMap[] = {5, 6, 7, 8, 9, 10, 11, 12}; | |
byte pinCount = sizeof(pinMap) / sizeof(byte); | |
int buttonPressTime = 250; // milliseconds | |
void setup(){ | |
Serial.begin(115200); | |
for (byte index = 0; index < pinCount; index ++) { | |
pinMode(pinMap[index], OUTPUT); | |
digitalWrite(pinMap[index], LOW); | |
} | |
} | |
void loop() { | |
if (Serial.available()) { | |
byte button = Serial.read() - '0' - 1; // Convert ASCII to button number | |
if (button >= 0 && button < pinCount) pressButton(button); | |
} | |
} | |
void pressButton(byte button) { | |
Serial.print("Button ON: "); | |
Serial.println(button); | |
digitalWrite(pinMap[button], HIGH); | |
delay(buttonPressTime); | |
digitalWrite(pinMap[button], LOW); | |
Serial.print("Button OFF: "); | |
Serial.println(button); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment