Created
August 12, 2014 00:41
-
-
Save blakejakopovic/a4bd64f2bb9561edd3df to your computer and use it in GitHub Desktop.
Spark Core Firmata Example
This file contains hidden or 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
| #include "firmata-spark/firmata-spark.h" | |
| TCPServer server = TCPServer(5678); | |
| TCPClient client; | |
| bool new_client = true; | |
| void setup() | |
| { | |
| // start listening for clients | |
| server.begin(); | |
| // Make sure your Serial Terminal app is closed before powering your Core | |
| Serial.begin(9600); | |
| // Now open your Serial Terminal, and hit any key to continue! | |
| while(!Serial.available()) SPARK_WLAN_Loop(); | |
| Serial.println(WiFi.localIP()); | |
| // Serial.println(WiFi.subnetMask()); | |
| // Serial.println(WiFi.gatewayIP()); | |
| // Serial.println(WiFi.SSID()); | |
| } | |
| void loop() | |
| { | |
| if (client.connected()) | |
| { | |
| if (new_client) | |
| { | |
| Firmata.begin(client); | |
| new_client = false; | |
| Serial.println("New client connected"); | |
| } | |
| Serial.println("> Hello world"); | |
| Firmata.sendString("Hello world"); | |
| } else { | |
| new_client = true; | |
| client = server.available(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment