Skip to content

Instantly share code, notes, and snippets.

@chrishuan9
Created April 11, 2014 08:08
Show Gist options
  • Save chrishuan9/10448851 to your computer and use it in GitHub Desktop.
Save chrishuan9/10448851 to your computer and use it in GitHub Desktop.
Arduino Yun Server Box
#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