Created
June 12, 2016 21:03
-
-
Save luca020400/3242192cd6d1eae2891d8f6d61f53aea to your computer and use it in GitHub Desktop.
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
char inData[256]; // Allocate some space for the string | |
char inChar = -1; // Where to store the character read | |
byte index = 0; // Index into array; where to store the character | |
void read_uart() { | |
while (Serial.available() > 0) { | |
if (index < 256) { | |
inChar = Serial.read(); // Read a character | |
inData[index] = inChar; // Store it | |
index++; // Increment where to write next | |
inData[index] = '\0'; // Null terminate the string | |
} | |
} | |
if (strcmp(inData, "") != 0) { | |
Serial.println(inData); | |
for (int i = 0; i < 256; i++) { | |
inData[i] = 0; | |
} | |
index = 0; | |
return; | |
} | |
return; | |
} | |
void setup() { | |
Serial.begin(9600); | |
Serial.write("Power On"); | |
} | |
void loop() | |
{ | |
read_uart(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment