Advertisement
kubbur

Untitled

Mar 20th, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.63 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Ethernet.h>
  3. #include <Servo.h>
  4.  
  5. byte mac[] = { 0x90, 0xa2, 0xda, 0x0d, 0x7c, 0xa9 };   //physical mac address 90-a2-da-0d-7c-a9
  6. byte ip[] = { 192, 168, 1, 178 };                      // ip in lan (that's what you need to use in your browser. ("192.168.1.178")
  7. byte gateway[] = { 192, 168, 1, 254 };                   // internet access via router
  8. byte subnet[] = { 255, 255, 255, 0 };                  //subnet mask
  9. EthernetServer server(1432);                             //server port    
  10. String readString;
  11.  
  12. Servo servo1;
  13. int analogPin = 1;
  14.  
  15. void setup()
  16. { //serialbegin, pinmode, servo, ethernet, startingsound
  17.     Serial.begin(9600);
  18.     pinMode(3, OUTPUT);
  19.     servo1.attach(7);
  20.    
  21.     Ethernet.begin(mac, ip, gateway, subnet);
  22.     server.begin();
  23.     Serial.print("server is at ");
  24.     Serial.println(Ethernet.localIP());
  25.    
  26.     //startingsound
  27.     tone (3, 800, 100);
  28.     delay (200);
  29.     tone (3, 800, 100);
  30.     delay (200);
  31.     tone (3, 800, 100);
  32.     delay (200);
  33. }
  34. void loop1() //default position
  35. {
  36.     servo1.write(90);
  37.     delay (200);
  38. }
  39. void loop2() //coffie machine on
  40. {
  41.     servo1.write (64);
  42.     delay (200);
  43. }
  44. void loop3() //waiting for water to heat
  45. {
  46.     delay (100000);
  47. }
  48. void loop4() //pushing the cup button
  49. {
  50.     servo1.write (118);
  51.     delay(200);
  52.    
  53. }
  54. void loop5()
  55. {
  56.     delay (30000); //waiting while coffie is pouring
  57.     tone (3, 800, 200);
  58.     delay (200);
  59.     tone (3, 800, 200);
  60.     int changepad = 1;
  61. }
  62. void loop()
  63. {
  64.     EthernetClient client = server.available();
  65.     if (client)
  66.     {
  67.         while (client.connected())
  68.         {
  69.             if (client.available())
  70.             {
  71.                 char c = client.read();
  72.                 if (readString.length() < 100)
  73.                 {
  74.                     readString += c;
  75.                 }
  76.                
  77.                 if (c == '\n')
  78.                 {
  79.                     client.println("HTTP/1.1 200 OK"); //send new page
  80.                     client.println("Content-Type: text/html; charset=utf-8");
  81.                     client.println();    
  82.                     client.println("<HTML>");
  83.                     client.println("<HEAD>");
  84.                     client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
  85.                     client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
  86.                     client.println("<link rel='stylesheet' type='text/css' href='http://randomnerdtutorials.com/ethernetcss.css' />");
  87.                     client.println("<TITLE>kubburs automatic coffie machine</TITLE>");
  88.                     client.println("</HEAD>");
  89.                     client.println("<BODY>");
  90.                     client.println("<H1>kubburs automatic coffie machine</H1>");
  91.                     client.println("<hr />");
  92.                     client.println("<br />");  
  93.                     client.println("<H2>Arduino with Ethernet Shield</H2>");
  94.                     client.println("<br />");  
  95.                     client.println("<a href=\"/?button1\"\">Turn on/off coffie machine</a>");
  96.                     client.println("<a href=\"/?button2\"\">Pour coffie</a><br />");  
  97.                     client.println("<br />");    
  98.                     client.println("<br />");
  99.                     client.println("<a href=\"/?button3\"\">make me a coffie</a>");
  100.                     client.println("<a href=\"/?button4\"\">make me 2 coffies</a><br />");
  101.                     client.println("<br />");    
  102.                     client.println("<br />");
  103.                     client.println("<a href=\"/?button5\"\">make me 3 coffies</a>");
  104.                     client.println("<a href=\"/?button6\"\">piezo element</a><br />");
  105.                     client.println("</BODY>");
  106.                     client.println("</HTML>");
  107.                    
  108.                     delay(1);
  109.                     client.stop();
  110.                     int val = 1;
  111.                     val = analogRead(analogPin);
  112.                     int changepad;
  113.                    
  114.                     if (val > 100)
  115.                     {
  116.                         int changepad = 0;
  117.                     }
  118.                    
  119.                     if (readString.indexOf("?button1") > 0 && changepad == 0 && val == 0)
  120.                     {
  121.                         loop1();
  122.                         loop2();
  123.                         loop1();
  124.                         loop3();
  125.                         loop4();
  126.                         loop1();
  127.                         loop5();
  128.                     }
  129.                     readString="";
  130.                 }
  131.             }
  132.         }
  133.     }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement