Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1.  
  2. #include <SPI.h>
  3. #include <Ethernet.h>
  4. #include <UTFT.h>
  5. extern uint8_t SmallFont[];
  6. byte mac[] = {
  7. 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
  8. };
  9. IPAddress ip(10, 80, 45, 254);
  10. EthernetServer server(80);
  11. UTFT myGLCD(ITDB28,A5,A4,A3,A2);
  12. void setup()
  13. {
  14. randomSeed(analogRead(0));
  15. myGLCD.InitLCD();
  16. myGLCD.setFont(SmallFont);
  17. //Added bit of code for ethernet support
  18. Ethernet.begin(mac, ip);
  19. server.begin();
  20. myGLCD.clrScr();
  21. myGLCD.setColor(255, 0, 0);
  22. myGLCD.fillRect(0, 0, 319, 13);
  23. myGLCD.setColor(64, 64, 64);
  24. myGLCD.fillRect(0, 226, 319, 239);
  25. myGLCD.setColor(255, 255, 255);
  26. myGLCD.setBackColor(255, 0, 0);
  27. myGLCD.print("* UTFT TEST WORKING *", CENTER, 1);
  28.  
  29. }
  30. void loop()
  31. {
  32. int buf[318];
  33. int x, x2;
  34. int y, y2;
  35. int r;
  36.  
  37.  
  38.  
  39. EthernetClient client = server.available();
  40. if (client) {
  41.  
  42. myGLCD.setBackColor(0, 0, 0);
  43. myGLCD.setColor(255, 255, 255);
  44. myGLCD.print("new client", CENTER, 16);
  45. delay(10);
  46. boolean currentLineIsBlank = true;
  47. while (client.connected()) {
  48. if (client.available()) {
  49. char c = client.read();
  50. if (c == '\n' && currentLineIsBlank) {
  51. // send a standard http response header
  52. client.println("HTTP/1.1 200 OK");
  53. client.println("Content-Type: text/html");
  54. client.println("Connection: close"); // the connection will be closed after completion of the response
  55. client.println("Refresh: 5"); // refresh the page automatically every 5 sec
  56. client.println();
  57. client.println("<!DOCTYPE HTML>");
  58. client.println("<html>");
  59. for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
  60. int sensorReading = analogRead(analogChannel);
  61. client.print("analog input ");
  62. client.print(analogChannel);
  63. client.print(" is ");
  64. client.print(sensorReading);
  65. client.println("<br />");
  66. }
  67. client.println("</html>");
  68. break;
  69. }
  70. if (c == '\n') {
  71. currentLineIsBlank = true;
  72. } else if (c != '\r') {
  73. currentLineIsBlank = false;
  74. }
  75. }
  76. }
  77. delay(1);
  78. client.stop();
  79. myGLCD.print("client disconnected", CENTER, 16);
  80. delay(10);
  81. myGLCD.setColor(0, 0, 0);
  82. myGLCD.fillRect(0, 16, 319, 32);
  83. Ethernet.maintain();
  84.  
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement