Created
July 16, 2017 05:10
-
-
Save yandod/64bbcd87ff5c7c8e00712aca1e1c849f to your computer and use it in GitHub Desktop.
testing Arduino serial interaction
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
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