Created
August 31, 2015 13:53
-
-
Save joffilyfe/53a28b39e9226388854f to your computer and use it in GitHub Desktop.
Recebendo comandos via porta serial no Arduino Mega
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
void setup() { | |
// Open serial communications and wait for port to open: | |
Serial.begin(9600); | |
while (!Serial); | |
// send an intro: | |
Serial.println("\nSerial INPUT!"); | |
} | |
void loop() { | |
// Read serial input: | |
while (Serial.available() > 0) { | |
int input = Serial.read(); | |
Serial.println(input); | |
Serial.println((char)input); | |
if (isDigit(input)) { | |
int number = (int)(input - 48); | |
blink_led(number); | |
} | |
} | |
} | |
void blink_led(int led) { | |
digitalWrite(led, HIGH); | |
delay(1000); | |
digitalWrite(led, LOW); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment