Skip to content

Instantly share code, notes, and snippets.

@AlexanderSavochkin
Created July 23, 2014 23:04
Show Gist options
  • Save AlexanderSavochkin/5c5ab3cd8826a21e6fc2 to your computer and use it in GitHub Desktop.
Save AlexanderSavochkin/5c5ab3cd8826a21e6fc2 to your computer and use it in GitHub Desktop.
Arduino hardware serial interconnection example
enum { LED_PIN = 13 };
void setup()
{
pinMode(LED_PIN, OUTPUT);
Serial.begin(9600);
}
void loop()
{
if (Serial.available()) //New data arrived
{
char command = Serial.read();
switch (command)
{
case '1':
Serial.println("Hello");
break;
case '2':
for (int i = 1; i < 5; ++i)
{
digitalWrite(LED_PIN, HIGH);
delay(50);
digitalWrite(LED_PIN, LOW);
delay(50);
}
break;
default:
Serial.println('?'); //Not recognized commands
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment