Skip to content

Instantly share code, notes, and snippets.

@amateusz
Last active May 24, 2018 14:23
Show Gist options
  • Save amateusz/23222733c40bbb4b73d507157208654a to your computer and use it in GitHub Desktop.
Save amateusz/23222733c40bbb4b73d507157208654a to your computer and use it in GitHub Desktop.
//// 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