Advertisement
kubbur

Untitled

Mar 18th, 2014
939
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.00 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. servo1.write (on);
  187. Serial.println("turning on coffie machine");
  188. delay(buttonpush);
  189.  
  190. servo1.write(def);
  191. Serial.println("heating water");
  192. delay(longstop);
  193.  
  194. servo1.write(cup);
  195. Serial.println("making coffie");
  196. delay(buttonpush);
  197.  
  198. servo1.write(def);
  199. delay(pouringcoffie);
  200.  
  201. servo1.write(on);
  202. Serial.println("turning off coffie machine");
  203. delay(buttonpush);
  204.  
  205. servo1.write(def);
  206. delay(1000);
  207. Serial.println("coffie machine is off");
  208.  
  209. digitalWrite(led, LOW);
  210. }
  211. else
  212. {
  213. Serial.println("lok er opid");
  214. tone (3, 200, 100);
  215. }
  216. }
  217. ///////////////////////////////////////////////////////////////
  218.  
  219. //make me 2 coffies
  220. if (readString.indexOf("?button4") > 0)
  221. {
  222. if (val == 0){
  223. digitalWrite(led, HIGH);
  224.  
  225. Serial.println("beginning to make coffie");
  226.  
  227. tone (3, 800, 100);
  228. delay (200);
  229. tone (3, 800, 100);
  230. delay (200);
  231.  
  232. servo1.write(def);
  233. delay(buttonpush);
  234. servo1.write (on);
  235. Serial.println("turning on coffie machine");
  236. delay(buttonpush);
  237.  
  238. servo1.write(def);
  239. Serial.println("heating water");
  240. delay(longstop);
  241.  
  242. servo1.write(cup);
  243. Serial.println("making coffie");
  244. delay(buttonpush);
  245.  
  246. servo1.write(def);
  247. delay(heatingwater);
  248.  
  249. Serial.println("blinking piezo ");
  250. tone (3, 500, 500);
  251. delay(pouringcoffie);
  252.  
  253. servo1.write(cup);
  254. Serial.println("making coffie");
  255. delay(buttonpush);
  256.  
  257. servo1.write(def);
  258. delay(pouringcoffie);
  259.  
  260. servo1.write(on);
  261. Serial.println("turning off coffie machine");
  262. delay(buttonpush);
  263.  
  264. servo1.write(def);
  265. delay(1000);
  266. Serial.println("coffie machine is off");
  267.  
  268.  
  269. digitalWrite(led, LOW);
  270. }
  271. else
  272. {
  273. Serial.println("lok er opid");
  274. tone (3, 200, 100);
  275. }
  276. }
  277. ////////////////////////////////////////////////////////////////
  278.  
  279.  
  280. //make me 3 coffies
  281. if (readString.indexOf("?button5") > 0)
  282. {
  283. if (val == 0){
  284. digitalWrite(led, HIGH);
  285.  
  286.  
  287. servo1.write(def);
  288. Serial.println("beginning to make coffie");
  289.  
  290. tone (3, 800, 100);
  291. delay (200);
  292. tone (3, 800, 100);
  293. delay (200);
  294.  
  295. servo1.write (on);
  296. Serial.println("turning on coffie machine");
  297. delay(buttonpush);
  298.  
  299. servo1.write(def);
  300. Serial.println("heating water");
  301. delay(longstop);
  302.  
  303. servo1.write(cup);
  304. Serial.println("making coffie");
  305. delay(buttonpush);
  306.  
  307. servo1.write(def);
  308. delay(heatingwater);
  309.  
  310. Serial.println("blinking piezo ");
  311. tone (3, 500, 500);
  312. delay(pouringcoffie);
  313.  
  314. servo1.write(cup);
  315. Serial.println("making coffie");
  316. delay(buttonpush);
  317.  
  318. servo1.write(def);
  319. delay(heatingwater);
  320.  
  321. Serial.println("blinking piezo ");
  322. tone (3, 500, 500);
  323. delay(pouringcoffie);
  324.  
  325. servo1.write(cup);
  326. Serial.println("making coffie");
  327. delay(buttonpush);
  328.  
  329. servo1.write(def);
  330. delay(pouringcoffie);
  331.  
  332. Serial.println("blinking piezo ");
  333. tone (3, 500, 500);
  334.  
  335. servo1.write(on);
  336. Serial.println("turning off coffie machine");
  337. delay(buttonpush);
  338.  
  339. servo1.write(def);
  340. Serial.println("coffie machine is off");
  341. delay(1000);
  342.  
  343. digitalWrite(led, LOW);
  344. }
  345. else
  346. {
  347. Serial.println("lok er opid");
  348. tone (3, 200, 100);
  349. }
  350. }
  351.  
  352. /////////////////////////////////////////////////////////////////
  353.  
  354. //make a noise with piezo
  355. if (readString.indexOf("?button6") > 0)
  356. {
  357.  
  358. digitalWrite(led, HIGH);
  359. Serial.println("blinking piezo ");
  360.  
  361. //tone(pin, frequency, duration)
  362. tone (3, 500, 500);
  363. digitalWrite(led, LOW);
  364. }
  365. /////////////////////////////////////////////////////////////////////////////
  366. //clearing string for next read
  367. readString="";
  368.  
  369. }
  370. }
  371. }
  372. }
  373. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement