Last active
May 24, 2018 14:23
-
-
Save amateusz/23222733c40bbb4b73d507157208654a to your computer and use it in GitHub Desktop.
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
//// before setup | |
const byte FIRST_QUESTION = '?'; | |
const byte FIRST_RESPONSE = 'T'; | |
//// void setup() here | |
\\\\ end of setup() | |
//// void loop() here | |
// put it in the loop | |
if (Serial.available()) { | |
char first = Serial.read(); | |
if (first == FIRST_QUESTION) { | |
Serial.write(FIRST_RESPONSE); | |
} | |
else { | |
if (first >= '0' && first <= '3'){ | |
char second = Serial.read(); | |
if (second == 'J' || second == 'S'){ | |
unsigned byte trackNumber = first - '0'; // number between 0-3 | |
char category = second; // char 'J' or 'S' | |
// now you can use those variables later on | |
} | |
} | |
else { | |
Serial.flush(); | |
break; | |
} | |
while (Serial.read() != '\r'){ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment