Skip to content

Instantly share code, notes, and snippets.

@zuk
Created August 28, 2012 21:22
Show Gist options
  • Select an option

  • Save zuk/3504472 to your computer and use it in GitHub Desktop.

Select an option

Save zuk/3504472 to your computer and use it in GitHub Desktop.
read serial character in arduino
#include <stdio.h>
char cmd;
#define CMD_ROCK 'r'
#define CMD_PAPER 'p'
#define CMD_SCISSORS 's'
void setup() {
Serial.begin(9600);
}
void loop() {
while (Serial.available()) {
cmd = Serial.read();
got_command(cmd);
}
}
void got_command(char cmd) {
switch (cmd) {
case CMD_ROCK:
// got rock!
break;
case CMD_PAPER:
// got paper!
break;
case CMD_SCISSORS:
// got scissors!
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment