Advertisement
Guest User

controle 2 led arduino

a guest
Apr 28th, 2013
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.62 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. int Pin2 = 2;
  15. int Pin3 = 3;
  16. boolean flag = true;
  17.  
  18. String Meldung = String("");
  19. boolean Pin2ON = false;
  20. boolean Pin3ON = false;
  21. boolean refresh = false;
  22.  
  23. void setup() {
  24. pinMode(Pin3, OUTPUT);
  25. pinMode(Pin2, OUTPUT);
  26.  
  27.  
  28. Serial.begin(9600);
  29. while (!Serial) {
  30. ;
  31. }
  32.  
  33.  
  34. Ethernet.begin(mac, ip, gateway, subnet);
  35. server.begin();
  36. Serial.print("server is at ");
  37. Serial.println(Ethernet.localIP());
  38. }
  39.  
  40.  
  41. void loop() {
  42.  
  43. EthernetClient client = server.available();
  44. if (client) {
  45. Serial.println("new client");
  46.  
  47. boolean currentLineIsBlank = true;
  48. while (client.connected()) {
  49. if (client.available()) {
  50. char c = client.read();
  51. Serial.write(c);
  52. //--------------------------------------------------------------------------------------
  53. //read char by char HTTP request
  54. if (Meldung.length() < 12) {
  55. //store characters to string
  56. //Meldung.append(c); //removed by Katsu
  57. Meldung = Meldung + c; // insert by Katsu
  58. // very simple but it works...
  59. }
  60. //-----------------------------------------------------------------------------------------*/
  61. // if you've gotten to the end of the line (received a newline
  62. // character) and the line is blank, the http request has ended,
  63. // so you can send a reply
  64. if (c == '\n' && currentLineIsBlank) {
  65. //--------------------------------------------------------------------------------------------
  66. if(Meldung.indexOf("2=all") > -1) {
  67. digitalWrite(Pin2, LOW);
  68. Serial.println("Pin 2 allumer!");
  69. Pin2ON = true;
  70. flag = true;
  71. }
  72. if(Meldung.indexOf("2=ete") > -1){
  73. digitalWrite(Pin2, HIGH);
  74. Serial.println("Pin 2 éteindre!");
  75. Pin2ON = false;
  76. flag = true;
  77. }
  78. if(Meldung.indexOf("3=all") > -1) {
  79. digitalWrite(Pin3, LOW);
  80. Serial.println("Pin 3 allumer!");
  81. Pin3ON = true;
  82. flag = true;
  83. }
  84. if(Meldung.indexOf("3=ete") > -1){
  85. digitalWrite(Pin3, HIGH);
  86. Serial.println("Pin 3 éteindre!");
  87. Pin3ON = false;
  88. flag = true;
  89. }
  90.  
  91. if(Meldung.indexOf("all=to") > -1){
  92. digitalWrite(Pin2, HIGH);
  93. digitalWrite(Pin3, HIGH);
  94. Serial.println("tout éteindre!");
  95. Pin2ON = false;
  96. Pin3ON = false;
  97. flag = true;
  98. }
  99.  
  100. if(Meldung.indexOf("ref=ref") > -1){
  101. refresh = true;
  102. }
  103. else {
  104. refresh = false;
  105. }
  106.  
  107. //-----------------------------------------------------------------------------------------------*/
  108. Meldung="";
  109. // send a standard http response header
  110. client.println("HTTP/1.1 200 OK");
  111. client.println("Content-Type: text/html");
  112. client.println("Connnection: close");
  113. client.println();
  114. client.println("<!DOCTYPE HTML>");
  115. client.println("<html>");
  116. client.print("<head>");
  117. client.print("<title>Arduino de chambre</title>");
  118. // add a meta refresh tag, so the browser pulls again every 5 seconds:
  119.  
  120. // Diese Zeile für den automatischen Abruf wieder einfügen; simuliert dann aber einen Mausklick auf das erste input-Feld.
  121. // kann man sicher ändern, ich weiß aber im Moment nicht wie.
  122. // client.println("<meta http-equiv=\"refresh\" content=\"5\">");
  123. // output the value of each analog input pin
  124. client.println("</head>");
  125. client.print("<body bgcolor='#AAAAAA'>");
  126. //--------------------------HTML------------------------
  127. if (flag) {
  128.  
  129.  
  130. client.println("<br><hr />");
  131. client.print("<h1><div align='center'>");
  132. client.print("<font color='#2076CD'>Chambre de thibault BOULLIER ");
  133. client.println("</font></div></h1>");
  134. client.println("<hr /><br>");
  135.  
  136.  
  137. client.println("<br/>");
  138. client.print("<form method=get>");
  139. client.print("<input type=submit name=ref value='refresh'>");
  140. client.println("</form></td>");
  141.  
  142. if (refresh) {
  143. client.println("<meta http-equiv=\"refresh\" content=\"5\">");
  144. }
  145.  
  146.  
  147. client.println("<div align='left'>");
  148. client.println("<br>");
  149. client.println("<table border='1' width='500' cellpadding='5'>");
  150. client.println("<tr bgColor='#222222'>");
  151. client.print("<td bgcolor='#222222'>");
  152. client.print("<font face='Verdana' color='#CFCFCF' size='2'>");
  153. client.println("led 2<br></font></td>");
  154.  
  155. client.print("<td align='center' bgcolor='#222222'>");
  156. client.print("<form method=get>");
  157. client.print("<input type=submit name=2 value='allumer'>");
  158. client.println("</form></td>");
  159. client.print("<td align='center' bgcolor='#222222'>");
  160. client.print("<form method=get>");
  161. client.print("<input type=submit name=2 value='eteindre'>");
  162. client.println("</form></td>");
  163. client.print("<td align='center'>");
  164.  
  165. if (Pin2ON) {
  166. client.print("<font color='green' size='5'>ON");
  167. } else {
  168. client.print("<font color='#CFCFCF' size='5'>OFF");
  169. }
  170. client.println("</font></td></tr>");
  171. client.println("<tr bgColor='#222222'>");
  172. client.print("<td bgcolor='#222222'>");
  173. client.print("<font face='Verdana' color='#CFCFCF' size='2'>");
  174. client.println("led 3<br></font></td>");
  175. client.print("<td align='center' bgcolor='#222222'>");
  176. client.println("<form method=get><input type=submit name=3 value='allumer'></form></td>");
  177. client.print("<td align='center' bgcolor='#222222'>");
  178. client.println("<form method=get><input type=submit name=3 value='eteindre'></form></td>");
  179. client.print("<td align='center'>");
  180.  
  181. if (Pin3ON) {
  182. client.print("<font color='green' size='5'>ON");
  183. } else {
  184. client.print("<font color='#CFCFCF' size='5'>OFF");
  185. }
  186. client.println("</font></td></tr>");
  187. client.println("</table>");
  188. client.println("<br>");
  189. client.print("<form method=get>");
  190. client.print("<input type=submit name=all value='tout eteindre'>");
  191. client.println("</form>"); //*/
  192. client.println("</body>");
  193. }
  194. //--------------------------------------------------------------------------------------------
  195. client.println("</html>");
  196. temp = temp +1; // Damit sich auch was bewegt auf dem Bildschirm
  197. break; //wozu?
  198. }
  199. if (c == '\n') {
  200. // you're starting a new line
  201. currentLineIsBlank = true;
  202. }
  203. else if (c != '\r') {
  204. // you've gotten a character on the current line
  205. currentLineIsBlank = false;
  206. }
  207. }
  208. }
  209. // give the web browser time to receive the data
  210. delay(1);
  211. // close the connection:
  212. client.stop();
  213. Serial.println("client disonnected");
  214. }
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement