Skip to content

Instantly share code, notes, and snippets.

@col
Created November 12, 2014 02:00
Show Gist options
  • Save col/9ad7fca60a7a463f7de9 to your computer and use it in GitHub Desktop.
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.
#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