Created
November 12, 2014 02:00
-
-
Save col/9ad7fca60a7a463f7de9 to your computer and use it in GitHub Desktop.
This is the first Arduino script we used to run the cocktail maker prototype via wifi using an Arduino Yun.
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> | |
YunServer server; | |
void setup() { | |
Serial.begin(9600); | |
pinMode(13,OUTPUT); | |
Bridge.begin(); | |
server.listenOnLocalhost(); | |
server.begin(); | |
} | |
void loop() { | |
YunClient client = server.accept(); | |
if (client) { | |
process(client); | |
client.stop(); | |
} | |
delay(50); | |
} | |
void process(YunClient client) { | |
String command = client.readStringUntil('/'); | |
if (command == "drink") { | |
drinkCommand(client); | |
} | |
} | |
void drinkCommand(YunClient client) { | |
int pin, seconds; | |
pin = client.parseInt(); | |
Serial.print("Pin:"); | |
Serial.println(pin); | |
if (client.read() == '/') { | |
seconds = client.parseInt(); | |
Serial.print("Seconds:"); | |
Serial.println(seconds); | |
digitalWrite(pin, HIGH); | |
delay(seconds * 1000); | |
digitalWrite(pin, LOW); | |
} | |
client.println("Enjoy your drink!"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment