Skip to content

Instantly share code, notes, and snippets.

@geekscape
Created July 3, 2009 23:16
Show Gist options
  • Save geekscape/140366 to your computer and use it in GitHub Desktop.
Save geekscape/140366 to your computer and use it in GitHub Desktop.
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