Advertisement
Guest User

Untitled

a guest
Jan 2nd, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1.  
  2. #include <SPI.h>
  3. #include <Ethernet.h>
  4.  
  5. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
  6. byte ip[] = { 00000000000 }; // ip in lan
  7. byte gateway[] = { 0000000000 }; // internet access via router
  8. byte subnet[] = { 000000000000 }; //subnet mask
  9. EthernetServer server(80); //server port
  10.  
  11. String readString;
  12.  
  13. #define ledPin 27
  14. #define led2Pin 28
  15. #define led3Pin 29
  16.  
  17. void setup() {
  18.  
  19. pinMode(ledPin, OUTPUT); //pin selected to control
  20. pinMode(led2Pin, OUTPUT); //pin selected to control
  21. pinMode(led3Pin, OUTPUT); //pin selected to control
  22. //start Ethernet
  23. Ethernet.begin(mac, ip, gateway, gateway, subnet);
  24. server.begin();
  25.  
  26. //enable serial data print
  27. Serial.begin(9600);
  28. Serial.println("server multi pin button test 1.0"); // so I can keep track of what is loaded
  29. }
  30.  
  31. void loop() {
  32. // Create a client connection
  33. EthernetClient client = server.available();
  34. if (client) {
  35. while (client.connected()) {
  36. if (client.available()) {
  37. char c = client.read();
  38.  
  39. //read char by char HTTP request
  40. if (readString.length() < 30) {
  41.  
  42. //store characters to string
  43. readString += c;
  44. //Serial.print(c);
  45. }
  46.  
  47. //if HTTP request has ended
  48. if (c == '\n') {
  49.  
  50. ///////////////
  51. Serial.println(readString); //print to serial monitor for debuging
  52.  
  53. client.println("HTTP/1.1 200 OK"); //send new page
  54. client.println("Content-Type: text/html");
  55. client.println();
  56.  
  57. client.println("<HTML>");
  58. client.println("<HEAD>");
  59. client.println("<TITLE>Arduino</TITLE>");
  60. client.println("</HEAD>");
  61. client.println("<BODY>");
  62.  
  63. client.println("<H1><center>ARDUINO WEB BUTTON</center></H1>");
  64.  
  65. client.println("<br>");
  66.  
  67. // custom buttons
  68.  
  69. client.println("<table align='center' border=10 bgcolor='green' ><th><h2><div onmousedown='mDown(this,\"1ON\")' onmouseup='mUp(this,\"1OFF\")' style='background-color:'#D94A38';width:130px;height:30px;padding:10px;'>FRENTE</div></table>");
  70. client.println("<br>");
  71. client.println("<table align='center' border=10 bgcolor='green' ><th><h2><div onmousedown='mDown(this,\"2ON\")' onmouseup='mUp(this,\"2OFF\")' style='background-color:'#D94A38';width:130px;height:30px;padding:10px;'>ESQUERDA</div></table>");
  72. client.println("<br>");
  73. client.println("<table align='center' border=10 bgcolor='green' ><th><h2><div onmousedown='mDown(this,\"3ON\")' onmouseup='mUp(this,\"3OFF\")' style='background-color:'#D94A38';width:130px;height:30px;padding:10px;'>MARCHA RE</div></table>");
  74.  
  75. client.println("<script>function mDown(obj,comando){obj.style.backgroundColor='#1ec5e5';obj.innerHTML='ACESO';location.href=\"?\" + comando}");
  76. client.println("function mUp(obj,comando){obj.style.backgroundColor='#D94A38';obj.innerHTML='APAGADO';location.href=\"?\" + comando}</script>");
  77.  
  78. client.println("</BODY>");
  79. client.println("</HTML>");
  80.  
  81. delay(1);
  82.  
  83.  
  84. if(readString.indexOf("1ON") >= 0) {
  85. digitalWrite(ledPin, HIGH);
  86. }
  87. if(readString.indexOf("1OFF") >= 0) {
  88. digitalWrite(ledPin, LOW);
  89. }
  90. if(readString.indexOf("2ON") >= 0) {
  91. digitalWrite(led2Pin, HIGH);
  92. }
  93. if(readString.indexOf("2OFF") >= 0) {
  94. digitalWrite(led2Pin, LOW);
  95. }
  96. if(readString.indexOf("3ON") >= 0) {
  97. digitalWrite(led3Pin, HIGH);
  98. }
  99. if(readString.indexOf("3OFF") >= 0) {
  100. digitalWrite(led3Pin, LOW);
  101. }
  102.  
  103. //clearing string for next read
  104. readString = "";
  105. //stopping client
  106. client.stop();
  107. }
  108. }
  109. }
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement