Advertisement
kubbur

Untitled

Mar 19th, 2014
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.02 KB | None | 0 0
  1.  
  2.  
  3. #include <SPI.h>
  4. #include <Ethernet.h>
  5. #include <Servo.h>
  6.  
  7. byte mac[] = { 0x90, 0xa2, 0xda, 0x0d, 0x7c, 0xa9 }; //physical mac address 90-a2-da-0d-7c-a9
  8. byte ip[] = { 192, 168, 1, 178 }; // ip in lan (that's what you need to use in your browser. ("192.168.1.178")
  9. byte gateway[] = { 192, 168, 1, 254 }; // internet access via router
  10. byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
  11. EthernetServer server(1432); //server port
  12. String readString;
  13.  
  14. int piezo = 3;
  15. int led = 8;
  16. Servo servo1;
  17.  
  18. int analogPin = 1;
  19. int val = 0;
  20. int changepad = 0;
  21.  
  22. int bled = (200);
  23. int plink = (200);
  24. int ibyte = Serial.read();
  25.  
  26. int on = (64);
  27. int cup = (118);
  28. int def = (90);
  29.  
  30. long longstop = (100000);
  31. int pouringcoffie = (30000);
  32. int heatingwater = (21000);
  33. int buttonpush = (200);
  34.  
  35. void setup() {
  36. //Open serial communications and wait for port to open:
  37. Serial.begin(9600);
  38.  
  39.  
  40.  
  41. pinMode(led, OUTPUT);
  42. pinMode(piezo, OUTPUT);
  43.  
  44. servo1.attach(7);
  45.  
  46. //start the Ethernet connection and the server:
  47. Ethernet.begin(mac, ip, gateway, subnet);
  48. server.begin();
  49. Serial.print("server is at ");
  50. Serial.println(Ethernet.localIP());
  51.  
  52. //starting sound
  53. tone (3, 800, 100);
  54. delay (200);
  55. tone (3, 800, 100);
  56. delay (200);
  57. tone (3, 800, 100);
  58. delay (200);
  59. }
  60.  
  61.  
  62. void loop()
  63.  
  64.  
  65.  
  66.  
  67. {
  68. //Create a client connection
  69. EthernetClient client = server.available();
  70. if (client)
  71. {
  72. while (client.connected())
  73. {
  74. if (client.available())
  75. {
  76. char c = client.read();
  77.  
  78. //read char by char HTTP request
  79. if (readString.length() < 100)
  80. {
  81. //store characters to string
  82. readString += c;
  83. //Serial.print(c);
  84. }
  85.  
  86. //if HTTP request has ended
  87. if (c == '\n')
  88. {
  89. //Serial.println(readString); //print to serial monitor for debuging
  90.  
  91. client.println("HTTP/1.1 200 OK"); //send new page
  92. client.println("Content-Type: text/html; charset=utf-8");
  93. client.println();
  94. client.println("<HTML>");
  95. client.println("<HEAD>");
  96. client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
  97. client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
  98. client.println("<link rel='stylesheet' type='text/css' href='http://randomnerdtutorials.com/ethernetcss.css' />");
  99. client.println("<TITLE>kubburs automatic coffie machine</TITLE>");
  100. client.println("</HEAD>");
  101. client.println("<BODY>");
  102. client.println("<H1>kubburs automatic coffie machine</H1>");
  103. client.println("<hr />");
  104. client.println("<br />");
  105. client.println("<H2>Arduino with Ethernet Shield</H2>");
  106. client.println("<br />");
  107. client.println("<a href=\"/?button1\"\">Blink led</a>");
  108. client.println("<a href=\"/?button2\"\">Turn on/off coffie machine</a><br />");
  109. client.println("<br />");
  110. client.println("<br />");
  111. client.println("<a href=\"/?button3\"\">make me a coffie</a>");
  112. client.println("<a href=\"/?button4\"\">make me 2 coffies</a><br />");
  113. client.println("<br />");
  114. client.println("<br />");
  115. client.println("<a href=\"/?button5\"\">make me 3 coffies</a>");
  116. client.println("<a href=\"/?button6\"\">piezo element</a><br />");
  117. client.println("</BODY>");
  118. client.println("</HTML>");
  119.  
  120. delay(1);
  121. //stopping client
  122. client.stop();
  123.  
  124. //controls the Arduino if you press the buttons
  125. val = analogRead(analogPin);
  126.  
  127. if (val >= 100)
  128. {
  129. int changepad = 0;
  130. Serial.println("opid");
  131. }
  132. //blinking led
  133.  
  134. if (readString.indexOf("?button1") > 0)
  135. {
  136. if (val == 0){
  137. Serial.println("lok er lokad ");
  138.  
  139.  
  140. }
  141. else if (val >= 100){
  142. Serial.println("lok er opid ");
  143. }
  144.  
  145.  
  146. }
  147. ////////////////////////////////////////////////////////////////
  148.  
  149. //turn on/off coffie machine
  150. if (readString.indexOf("?button2") > 0)
  151. {
  152. if (changepad == 0){
  153.  
  154. if (val == 0){
  155. Serial.println("turning on/off coffie machine");
  156.  
  157. servo1.write(def);
  158. delay(buttonpush);
  159. servo1.write (on);
  160. delay(buttonpush);
  161. servo1.write(def);
  162. int changepad = 1;
  163. }
  164. }
  165. }
  166.  
  167.  
  168.  
  169. /////////////////////////////////////////////////////////////////
  170.  
  171. //make me a coffie
  172. if (readString.indexOf("?button3") > 0)
  173. {
  174. if (val == 0){
  175. digitalWrite(led, HIGH);
  176.  
  177. Serial.println("beginning to make coffie");
  178.  
  179. tone (3, 800, 100);
  180. delay (200);
  181. tone (3, 800, 100);
  182. delay (200);
  183.  
  184. servo1.write(def);
  185. delay(buttonpush);
  186.  
  187. servo1.write (on);
  188. Serial.println("turning on coffie machine");
  189. delay(buttonpush);
  190.  
  191. servo1.write(def);
  192. Serial.println("heating water");
  193. delay(longstop);
  194.  
  195. servo1.write(cup);
  196. Serial.println("making coffie");
  197. delay(buttonpush);
  198.  
  199. servo1.write(def);
  200. delay(pouringcoffie);
  201.  
  202. servo1.write(on);
  203. Serial.println("turning off coffie machine");
  204. delay(buttonpush);
  205.  
  206. servo1.write(def);
  207. delay(1000);
  208. Serial.println("coffie machine is off");
  209.  
  210. digitalWrite(led, LOW);
  211. }
  212. else
  213. {
  214. Serial.println("lok er opid");
  215. tone (3, 200, 100);
  216. }
  217. }
  218. ///////////////////////////////////////////////////////////////
  219.  
  220. //make me 2 coffies
  221. if (readString.indexOf("?button4") > 0)
  222. {
  223. if (val == 0){
  224. digitalWrite(led, HIGH);
  225.  
  226. Serial.println("beginning to make coffie");
  227.  
  228. tone (3, 800, 100);
  229. delay (200);
  230. tone (3, 800, 100);
  231. delay (200);
  232.  
  233. servo1.write(def);
  234. delay(buttonpush);
  235. servo1.write (on);
  236. Serial.println("turning on coffie machine");
  237. delay(buttonpush);
  238.  
  239. servo1.write(def);
  240. Serial.println("heating water");
  241. delay(longstop);
  242.  
  243. servo1.write(cup);
  244. Serial.println("making coffie");
  245. delay(buttonpush);
  246.  
  247. servo1.write(def);
  248. delay(heatingwater);
  249.  
  250. Serial.println("blinking piezo ");
  251. tone (3, 500, 500);
  252. delay(pouringcoffie);
  253.  
  254. servo1.write(cup);
  255. Serial.println("making coffie");
  256. delay(buttonpush);
  257.  
  258. servo1.write(def);
  259. delay(pouringcoffie);
  260.  
  261. servo1.write(on);
  262. Serial.println("turning off coffie machine");
  263. delay(buttonpush);
  264.  
  265. servo1.write(def);
  266. delay(1000);
  267. Serial.println("coffie machine is off");
  268.  
  269.  
  270. digitalWrite(led, LOW);
  271. }
  272. else
  273. {
  274. Serial.println("lok er opid");
  275. tone (3, 200, 100);
  276. }
  277. }
  278. ////////////////////////////////////////////////////////////////
  279.  
  280.  
  281. //make me 3 coffies
  282. if (readString.indexOf("?button5") > 0)
  283. {
  284. if (val == 0){
  285. digitalWrite(led, HIGH);
  286.  
  287.  
  288. servo1.write(def);
  289. Serial.println("beginning to make coffie");
  290.  
  291. tone (3, 800, 100);
  292. delay (200);
  293. tone (3, 800, 100);
  294. delay (200);
  295.  
  296. servo1.write (on);
  297. Serial.println("turning on coffie machine");
  298. delay(buttonpush);
  299.  
  300. servo1.write(def);
  301. Serial.println("heating water");
  302. delay(longstop);
  303.  
  304. servo1.write(cup);
  305. Serial.println("making coffie");
  306. delay(buttonpush);
  307.  
  308. servo1.write(def);
  309. delay(heatingwater);
  310.  
  311. Serial.println("blinking piezo ");
  312. tone (3, 500, 500);
  313. delay(pouringcoffie);
  314.  
  315. servo1.write(cup);
  316. Serial.println("making coffie");
  317. delay(buttonpush);
  318.  
  319. servo1.write(def);
  320. delay(heatingwater);
  321.  
  322. Serial.println("blinking piezo ");
  323. tone (3, 500, 500);
  324. delay(pouringcoffie);
  325.  
  326. servo1.write(cup);
  327. Serial.println("making coffie");
  328. delay(buttonpush);
  329.  
  330. servo1.write(def);
  331. delay(pouringcoffie);
  332.  
  333. Serial.println("blinking piezo ");
  334. tone (3, 500, 500);
  335.  
  336. servo1.write(on);
  337. Serial.println("turning off coffie machine");
  338. delay(buttonpush);
  339.  
  340. servo1.write(def);
  341. Serial.println("coffie machine is off");
  342. delay(1000);
  343.  
  344. digitalWrite(led, LOW);
  345. }
  346. else
  347. {
  348. Serial.println("lok er opid");
  349. tone (3, 200, 100);
  350. }
  351. }
  352.  
  353. /////////////////////////////////////////////////////////////////
  354.  
  355. //make a noise with piezo
  356. if (readString.indexOf("?button6") > 0)
  357. {
  358.  
  359. digitalWrite(led, HIGH);
  360. Serial.println("blinking piezo ");
  361.  
  362. //tone(pin, frequency, duration)
  363. tone (3, 500, 500);
  364. digitalWrite(led, LOW);
  365. }
  366. /////////////////////////////////////////////////////////////////////////////
  367. //clearing string for next read
  368. readString="";
  369.  
  370. }
  371. }
  372. }
  373. }
  374. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement