Advertisement
Guest User

contrôle 3 led arduino

a guest
Apr 28th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.13 KB | None | 0 0
  1.  
  2.  
  3. #include <SPI.h>
  4. #include <Ethernet.h>
  5.  
  6. byte mac[] = {0x90, 0xA2, 0xDA, 0x0D, 0xF0, 0xA4 };
  7. byte ip[] = { 192, 168, 1, 30 };
  8. byte gateway[] = { 192, 168, 0, 1 };
  9. byte subnet[] = { 255, 255, 255, 0 };
  10.  
  11. EthernetServer server(80);
  12.  
  13. int temp = 0;
  14.  
  15. int Pin2 = 2;
  16. int Pin3 = 3;
  17. int Pin4 = 5;
  18. int Pin5 = 6;
  19.  
  20. boolean Pin2ON = false;
  21. boolean Pin3ON = false;
  22. boolean Pin4ON = false;
  23. boolean Pin5ON = false;
  24.  
  25. int Pin6 = 7;
  26. int Pin7 = 8;
  27. int Pin8 = 9;
  28. int Pin9 = 11;
  29.  
  30. boolean Pin6ON = false;
  31. boolean Pin7ON = false;
  32. boolean Pin8ON = false;
  33. boolean Pin9ON = false;
  34.  
  35. boolean flag = true;
  36. String Meldung = String("");
  37. boolean refresh = false;
  38.  
  39. void setup() {
  40.  
  41. pinMode(Pin2, OUTPUT);
  42. pinMode(Pin3, OUTPUT);
  43. pinMode(Pin4, OUTPUT);
  44. pinMode(Pin5, OUTPUT);
  45.  
  46. pinMode(Pin6, INPUT);
  47. pinMode(Pin7, INPUT);
  48. pinMode(Pin8, INPUT);
  49. pinMode(Pin9, INPUT);
  50.  
  51. Serial.begin(9600);
  52. while (!Serial) {
  53. ;
  54. }
  55.  
  56.  
  57. Ethernet.begin(mac, ip, gateway, subnet);
  58. server.begin();
  59. Serial.print("server is at ");
  60. Serial.println(Ethernet.localIP());
  61. }
  62.  
  63.  
  64. void loop() {
  65.  
  66. EthernetClient client = server.available();
  67. if (client) {
  68. Serial.println("new client");
  69.  
  70. boolean currentLineIsBlank = true;
  71. while (client.connected()) {
  72. if (client.available()) {
  73. char c = client.read();
  74. Serial.write(c);
  75. //--------------------------------------------------------------------------------------
  76. //read char by char HTTP request
  77. if (Meldung.length() < 12) {
  78. //store characters to string
  79. //Meldung.append(c); //removed by Katsu
  80. Meldung = Meldung + c; // insert by Katsu
  81. // very simple but it works...
  82. }
  83. //-----------------------------------------------------------------------------------------*/
  84. // if you've gotten to the end of the line (received a newline
  85. // character) and the line is blank, the http request has ended,
  86. // so you can send a reply
  87. if (c == '\n' && currentLineIsBlank) {
  88. //--------------------------------------------------------------------------------------------
  89. if(Meldung.indexOf("2=on") > 0) {
  90. digitalWrite(Pin2, LOW);
  91. Serial.println("Pin 2 allumer!");
  92. Pin2ON = true;
  93. flag = true;
  94. }
  95. if(Meldung.indexOf("2=off") > 0){
  96. digitalWrite(Pin2, HIGH);
  97. Serial.println("Pin 2 éteindre!");
  98. Pin2ON = false;
  99. flag = true;
  100. }
  101.  
  102. if(Meldung.indexOf("3=on") > 0) {
  103. digitalWrite(Pin3, LOW);
  104. Serial.println("Pin 3 allumer!");
  105. Pin3ON = true;
  106. flag = true;
  107. }
  108. if(Meldung.indexOf("3=off") > 0){
  109. digitalWrite(Pin3, HIGH);
  110. Serial.println("Pin 3 éteindre!");
  111. Pin3ON = false;
  112. flag = true;
  113. }
  114.  
  115. if(Meldung.indexOf("4=on") > 0) {
  116. digitalWrite(Pin4, LOW);
  117. Serial.println("Pin 4 allumer!");
  118. Pin4ON = true;
  119. flag = true;
  120. }
  121. if(Meldung.indexOf("4=off") > 0){
  122. digitalWrite(Pin4, HIGH);
  123. Serial.println("Pin 4 éteindre!");
  124. Pin4ON = false;
  125. flag = true;
  126. }
  127.  
  128. if(Meldung.indexOf("all=to") > 0){
  129. digitalWrite(Pin2, HIGH);
  130. digitalWrite(Pin3, HIGH);
  131. digitalWrite(Pin4, HIGH);
  132. Serial.println("tout éteindre!");
  133. Pin2ON = false;
  134. Pin3ON = false;
  135. Pin4ON = false;
  136. flag = true;
  137. }
  138.  
  139. if(Meldung.indexOf("ref=ref") > 0){
  140. refresh = true;
  141. }
  142. else {
  143. refresh = false;
  144. }
  145.  
  146.  
  147.  
  148. //-----------------------------------------------------------------------------------------------*/
  149.  
  150. // send a standard http response header
  151. client.println("HTTP/1.1 200 OK");
  152. client.println("Content-Type: text/html");
  153. client.println("Connnection: close");
  154. client.println();
  155. client.println("<!DOCTYPE HTML>");
  156. client.println("<html>");
  157. client.print("<head>");
  158. client.print("<title>Arduino de chambre</title>");
  159. client.println("</head>");
  160. client.print("<body bgcolor='#AAAAAA'>");
  161.  
  162. //--------------------------HTML------------------------
  163. if (flag) {
  164.  
  165. client.println("<br><hr />");
  166. client.print("<h1><div align='center'>");
  167. client.print("<font color='#2076CD'>Chambre de thibault BOULLIER ");
  168. client.println("</font></div></h1>");
  169. client.println("<hr /><br>");
  170.  
  171.  
  172. client.println("<br/>");
  173. client.print("<form method=get>");
  174. client.print("<input type=submit name=ref value='refresh'>");
  175. client.println("</form></td>");
  176.  
  177. if (refresh) {
  178. client.println("<meta http-equiv=\"refresh\" content=\"5\">");
  179. }
  180.  
  181.  
  182. client.println("<div align='left'>");
  183. client.println("<br>");
  184.  
  185. client.println("<table border='1' width='500' cellpadding='5'>");
  186. client.println("<tr bgColor='#222222'>");
  187.  
  188. client.print("<td bgcolor='#222222'>");
  189. client.print("<font face='Verdana' color='#CFCFCF' size='2'>");
  190. client.println("led 2<br></font></td>");
  191.  
  192. client.print("<td align='center' bgcolor='#222222'>");
  193. client.print("<form method=get>");
  194. client.print("<input type=submit name=2 value='on'>");
  195. client.println("</form></td>");
  196.  
  197. client.print("<td align='center' bgcolor='#222222'>");
  198. client.print("<form method=get>");
  199. client.print("<input type=submit name=2 value='off'>");
  200. client.println("</form></td>");
  201.  
  202. client.print("<td align='center'>");
  203.  
  204. if (Pin2ON) {
  205. client.print("<font color='green' size='5'>ON");
  206. } else {
  207. client.print("<font color='#CFCFCF' size='5'>OFF");
  208. }
  209. client.println("</font></td></tr>");
  210.  
  211. client.println("<tr bgColor='#222222'>");
  212. client.print("<td bgcolor='#222222'>");
  213. client.print("<font face='Verdana' color='#CFCFCF' size='2'>");
  214. client.println("led 3<br></font></td>");
  215.  
  216. client.print("<td align='center' bgcolor='#222222'>");
  217. client.println("<form method=get><input type=submit name=3 value='on'></form></td>");
  218.  
  219. client.print("<td align='center' bgcolor='#222222'>");
  220. client.println("<form method=get><input type=submit name=3 value='off'></form></td>");
  221.  
  222. client.print("<td align='center'>");
  223.  
  224. if (Pin3ON) {
  225. client.print("<font color='green' size='5'>ON");
  226. } else {
  227. client.print("<font color='#CFCFCF' size='5'>OFF");
  228. }
  229. client.println("</font></td></tr>");
  230. client.println("<tr bgColor='#222222'>");
  231.  
  232. client.print("<td bgcolor='#222222'>");
  233. client.print("<font face='Verdana' color='#CFCFCF' size='2'>");
  234. client.println("led 4<br></font></td>");
  235.  
  236. client.print("<td align='center' bgcolor='#222222'>");
  237. client.print("<form method=get>");
  238. client.print("<input type=submit name=4 value='on'>");
  239. client.println("</form></td>");
  240.  
  241. client.print("<td align='center' bgcolor='#222222'>");
  242. client.print("<form method=get>");
  243. client.print("<input type=submit name=4 value='off'>");
  244. client.println("</form></td>");
  245.  
  246. client.print("<td align='center'>");
  247.  
  248. if (Pin4ON) {
  249. client.print("<font color='green' size='5'>ON");
  250. } else {
  251. client.print("<font color='#CFCFCF' size='5'>OFF");
  252. }
  253. client.println("</font></td></tr>");
  254. client.println("</table>");
  255. client.println("<br>");
  256. client.print("<form method=get>");
  257. client.print("<input type=submit name=all value='tout eteindre'>");
  258. client.println("</form>");
  259. client.println("</body>");
  260. }
  261. //--------------------------------------------------------------------------------------------
  262.  
  263. //-------------------------------------------------------------------------------
  264.  
  265. client.println("</html>");
  266. temp = temp +1; // Damit sich auch was bewegt auf dem Bildschirm
  267. break; //wozu?
  268. }
  269. if (c == '\n') {
  270. // you're starting a new line
  271. currentLineIsBlank = true;
  272. }
  273. else if (c != '\r') {
  274. // you've gotten a character on the current line
  275. currentLineIsBlank = false;
  276. }
  277. }
  278. }
  279. // give the web browser time to receive the data
  280. delay(1);
  281. // close the connection:
  282. client.stop();
  283. Serial.println("client disonnected");
  284. }
  285. Meldung="";
  286. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement