Skip to content

Instantly share code, notes, and snippets.

@joffilyfe
Created August 31, 2015 13:53
Show Gist options
  • Save joffilyfe/53a28b39e9226388854f to your computer and use it in GitHub Desktop.
Save joffilyfe/53a28b39e9226388854f to your computer and use it in GitHub Desktop.
Recebendo comandos via porta serial no Arduino Mega
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