Created
January 17, 2015 03:20
-
-
Save towynlin/a2b5d94aa4ed1fdb70a9 to your computer and use it in GitHub Desktop.
Show both serial and Wi-Fi working together
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
int last = 0; | |
char buf[256]; | |
int toSerial(String s) { | |
Serial.print("You said via REST API: "); | |
Serial.println(s); | |
memset(buf, 0, 256); | |
int charsRead = 0; | |
while (Serial.available() && charsRead < 255) { | |
buf[charsRead] = Serial.read(); | |
charsRead++; | |
delay(1); | |
} | |
if (0 < charsRead) { | |
Serial.print("You said over serial: "); | |
Serial.println(buf); | |
} else { | |
Serial.println("You haven't said anything over serial lately."); | |
} | |
return charsRead; | |
} | |
void setup() { | |
Serial.begin(9600); | |
Spark.function("to-serial", toSerial); | |
} | |
void loop() { | |
if (millis() - last > 5000) { | |
Serial.println("It's been 5 seconds."); | |
last = millis(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment