Skip to content

Instantly share code, notes, and snippets.

@yandod
Created July 16, 2017 05:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yandod/64bbcd87ff5c7c8e00712aca1e1c849f to your computer and use it in GitHub Desktop.
Save yandod/64bbcd87ff5c7c8e00712aca1e1c849f to your computer and use it in GitHub Desktop.
testing Arduino serial interaction
const int TESTPIN = 11;
String label = "Tick";
char buffer[33];
void setup() {
// put your setup code here, to run once:
pinMode(TESTPIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
int index = 0;
bool hasData = false;
while (Serial.available() > 0) {
hasData = true;
buffer[index] = Serial.read();
index++;
if (index >= 32) {
break;
}
}
buffer[index] = "\0";
if (hasData == true) {
label = buffer;
label.trim();
}
digitalWrite(TESTPIN, HIGH);
delay(500);
digitalWrite(TESTPIN, LOW);
delay(500);
Serial.println(label);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment