Created
April 11, 2014 08:08
-
-
Save chrishuan9/10448851 to your computer and use it in GitHub Desktop.
Arduino Yun Server Box
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 <Bridge.h> | |
#include <YunServer.h> | |
#include <YunClient.h> | |
#define PORT 6666 | |
YunServer server(PORT); | |
void setup() { | |
Serial.begin(115200); | |
Bridge.begin(); | |
server.noListenOnLocalhost(); | |
server.begin(); | |
} | |
void loop() { | |
YunClient client = server.accept(); | |
if(client.connected()){ | |
Serial.println("CLIENT CONNECTED!"); | |
String string = ""; | |
while(client.connected()){ | |
if(client.available()){ | |
char received = client.read(); | |
if(received != '\n' && received != 4){ | |
string += received; | |
} | |
if(received == '\n'){ | |
int val = atoi(&string[0]); | |
analogWrite(13, val); | |
analogWrite(6, val); | |
Serial.println(val); | |
string = ""; | |
} | |
if(received == 4){ | |
break; | |
} | |
} | |
} | |
client.stop(); | |
} | |
else { | |
Serial.println("no client connected, retrying"); | |
} | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment