Created
August 28, 2012 21:22
-
-
Save zuk/3504472 to your computer and use it in GitHub Desktop.
read serial character in arduino
This file contains hidden or 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
| #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