Created
July 23, 2014 20:52
-
-
Save AlexanderSavochkin/71255f1246d41258a34e to your computer and use it in GitHub Desktop.
Software serial interconnection
This file contains 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 <SoftwareSerial.h> | |
SoftwareSerial softSerial(10, 11); // RX, TX | |
enum { LED_PIN = 13 }; | |
void setup() | |
{ | |
pinMode(LED_PIN, OUTPUT); | |
softSerial.begin(9600); | |
} | |
void loop() | |
{ | |
if (softSerial.available()) //New data arrived | |
{ | |
char command = softSerial.read(); | |
switch (command) | |
{ | |
case '1': | |
softSerial.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: | |
softSerial.println('?'); //Not recognized commands | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment