Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Ethernet.h>
- #include <Servo.h>
- byte mac[] = { 0x90, 0xa2, 0xda, 0x0d, 0x7c, 0xa9 }; //physical mac address 90-a2-da-0d-7c-a9
- byte ip[] = { 192, 168, 1, 178 }; // ip in lan (that's what you need to use in your browser. ("192.168.1.178")
- byte gateway[] = { 192, 168, 1, 254 }; // internet access via router
- byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
- EthernetServer server(1432); //server port
- String readString;
- int piezo = 3;
- int led = 8;
- Servo servo1;
- int analogPin = 1;
- int val = 0;
- int changepad = 0;
- int bled = (200);
- int plink = (200);
- int ibyte = Serial.read();
- int on = (64);
- int cup = (118);
- int def = (90);
- long longstop = (100000);
- int pouringcoffie = (30000);
- int heatingwater = (21000);
- int buttonpush = (200);
- void setup() {
- //Open serial communications and wait for port to open:
- Serial.begin(9600);
- pinMode(led, OUTPUT);
- pinMode(piezo, OUTPUT);
- servo1.attach(7);
- //start the Ethernet connection and the server:
- Ethernet.begin(mac, ip, gateway, subnet);
- server.begin();
- Serial.print("server is at ");
- Serial.println(Ethernet.localIP());
- //starting sound
- tone (3, 800, 100);
- delay (200);
- tone (3, 800, 100);
- delay (200);
- tone (3, 800, 100);
- delay (200);
- }
- void loop()
- {
- //Create a client connection
- EthernetClient client = server.available();
- if (client)
- {
- while (client.connected())
- {
- if (client.available())
- {
- char c = client.read();
- //read char by char HTTP request
- if (readString.length() < 100)
- {
- //store characters to string
- readString += c;
- //Serial.print(c);
- }
- //if HTTP request has ended
- if (c == '\n')
- {
- //Serial.println(readString); //print to serial monitor for debuging
- client.println("HTTP/1.1 200 OK"); //send new page
- client.println("Content-Type: text/html; charset=utf-8");
- client.println();
- client.println("<HTML>");
- client.println("<HEAD>");
- client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
- client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
- client.println("<link rel='stylesheet' type='text/css' href='http://randomnerdtutorials.com/ethernetcss.css' />");
- client.println("<TITLE>kubburs automatic coffie machine</TITLE>");
- client.println("</HEAD>");
- client.println("<BODY>");
- client.println("<H1>kubburs automatic coffie machine</H1>");
- client.println("<hr />");
- client.println("<br />");
- client.println("<H2>Arduino with Ethernet Shield</H2>");
- client.println("<br />");
- client.println("<a href=\"/?button1\"\">Blink led</a>");
- client.println("<a href=\"/?button2\"\">Turn on/off coffie machine</a><br />");
- client.println("<br />");
- client.println("<br />");
- client.println("<a href=\"/?button3\"\">make me a coffie</a>");
- client.println("<a href=\"/?button4\"\">make me 2 coffies</a><br />");
- client.println("<br />");
- client.println("<br />");
- client.println("<a href=\"/?button5\"\">make me 3 coffies</a>");
- client.println("<a href=\"/?button6\"\">piezo element</a><br />");
- client.println("</BODY>");
- client.println("</HTML>");
- delay(1);
- //stopping client
- client.stop();
- //controls the Arduino if you press the buttons
- val = analogRead(analogPin);
- if (val >= 100)
- {
- int changepad = 0;
- Serial.println("opid");
- }
- //blinking led
- if (readString.indexOf("?button1") > 0)
- {
- if (val == 0){
- Serial.println("lok er lokad ");
- }
- else if (val >= 100){
- Serial.println("lok er opid ");
- }
- }
- ////////////////////////////////////////////////////////////////
- //turn on/off coffie machine
- if (readString.indexOf("?button2") > 0)
- {
- if (changepad == 0){
- if (val == 0){
- Serial.println("turning on/off coffie machine");
- servo1.write(def);
- delay(buttonpush);
- servo1.write (on);
- delay(buttonpush);
- servo1.write(def);
- int changepad = 1;
- }
- }
- }
- /////////////////////////////////////////////////////////////////
- //make me a coffie
- if (readString.indexOf("?button3") > 0)
- {
- if (val == 0){
- digitalWrite(led, HIGH);
- Serial.println("beginning to make coffie");
- tone (3, 800, 100);
- delay (200);
- tone (3, 800, 100);
- delay (200);
- servo1.write(def);
- delay(buttonpush);
- servo1.write (on);
- Serial.println("turning on coffie machine");
- delay(buttonpush);
- servo1.write(def);
- Serial.println("heating water");
- delay(longstop);
- servo1.write(cup);
- Serial.println("making coffie");
- delay(buttonpush);
- servo1.write(def);
- delay(pouringcoffie);
- servo1.write(on);
- Serial.println("turning off coffie machine");
- delay(buttonpush);
- servo1.write(def);
- delay(1000);
- Serial.println("coffie machine is off");
- digitalWrite(led, LOW);
- }
- else
- {
- Serial.println("lok er opid");
- tone (3, 200, 100);
- }
- }
- ///////////////////////////////////////////////////////////////
- //make me 2 coffies
- if (readString.indexOf("?button4") > 0)
- {
- if (val == 0){
- digitalWrite(led, HIGH);
- Serial.println("beginning to make coffie");
- tone (3, 800, 100);
- delay (200);
- tone (3, 800, 100);
- delay (200);
- servo1.write(def);
- delay(buttonpush);
- servo1.write (on);
- Serial.println("turning on coffie machine");
- delay(buttonpush);
- servo1.write(def);
- Serial.println("heating water");
- delay(longstop);
- servo1.write(cup);
- Serial.println("making coffie");
- delay(buttonpush);
- servo1.write(def);
- delay(heatingwater);
- Serial.println("blinking piezo ");
- tone (3, 500, 500);
- delay(pouringcoffie);
- servo1.write(cup);
- Serial.println("making coffie");
- delay(buttonpush);
- servo1.write(def);
- delay(pouringcoffie);
- servo1.write(on);
- Serial.println("turning off coffie machine");
- delay(buttonpush);
- servo1.write(def);
- delay(1000);
- Serial.println("coffie machine is off");
- digitalWrite(led, LOW);
- }
- else
- {
- Serial.println("lok er opid");
- tone (3, 200, 100);
- }
- }
- ////////////////////////////////////////////////////////////////
- //make me 3 coffies
- if (readString.indexOf("?button5") > 0)
- {
- if (val == 0){
- digitalWrite(led, HIGH);
- servo1.write(def);
- Serial.println("beginning to make coffie");
- tone (3, 800, 100);
- delay (200);
- tone (3, 800, 100);
- delay (200);
- servo1.write (on);
- Serial.println("turning on coffie machine");
- delay(buttonpush);
- servo1.write(def);
- Serial.println("heating water");
- delay(longstop);
- servo1.write(cup);
- Serial.println("making coffie");
- delay(buttonpush);
- servo1.write(def);
- delay(heatingwater);
- Serial.println("blinking piezo ");
- tone (3, 500, 500);
- delay(pouringcoffie);
- servo1.write(cup);
- Serial.println("making coffie");
- delay(buttonpush);
- servo1.write(def);
- delay(heatingwater);
- Serial.println("blinking piezo ");
- tone (3, 500, 500);
- delay(pouringcoffie);
- servo1.write(cup);
- Serial.println("making coffie");
- delay(buttonpush);
- servo1.write(def);
- delay(pouringcoffie);
- Serial.println("blinking piezo ");
- tone (3, 500, 500);
- servo1.write(on);
- Serial.println("turning off coffie machine");
- delay(buttonpush);
- servo1.write(def);
- Serial.println("coffie machine is off");
- delay(1000);
- digitalWrite(led, LOW);
- }
- else
- {
- Serial.println("lok er opid");
- tone (3, 200, 100);
- }
- }
- /////////////////////////////////////////////////////////////////
- //make a noise with piezo
- if (readString.indexOf("?button6") > 0)
- {
- digitalWrite(led, HIGH);
- Serial.println("blinking piezo ");
- //tone(pin, frequency, duration)
- tone (3, 500, 500);
- digitalWrite(led, LOW);
- }
- /////////////////////////////////////////////////////////////////////////////
- //clearing string for next read
- readString="";
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement