document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #include "SPI.h"
  2. #include "Ethernet.h"
  3. #include "WebServer.h"
  4.  
  5. static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
  6.  
  7. static uint8_t ip[] = { 192, 168, 0, 50 };
  8.  
  9.  
  10. #define PREFIX "/buzz"
  11. WebServer webserver(PREFIX, 80);
  12.  
  13. #define BUZZER_PIN 3
  14.  
  15.  
  16. int buzzDelay = 0;
  17.  
  18.  
  19. char toggle = 0;
  20.  
  21.  
  22. void buzzCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
  23. {
  24. if (type == WebServer::POST)
  25. {
  26. bool repeat;
  27. char name[16], value[16];
  28. do
  29. {
  30.  
  31. repeat = server.readPOSTparam(name, 16, value, 16);
  32.  
  33.  
  34. if (strcmp(name, "buzz") == 0)
  35. {
  36.  
  37. buzzDelay = strtoul(value, NULL, 10);
  38. }
  39. } while (repeat);
  40.  
  41.  
  42. server.httpSeeOther(PREFIX);
  43. return;
  44. }
  45.  
  46.  
  47. server.httpSuccess();
  48.  
  49.  
  50. if (type == WebServer::GET)
  51. {
  52.  
  53. P(message) =
  54. "<html><head><title>test buzzer computermuseo</title>"
  55. "<body>"
  56. "<h1>testa il tuo buzzer</h1>"
  57. "<form action='/buzz' method='POST'>"
  58. "<p><button name='buzz' value='0'>Turn if Off!</button></p>"
  59. "<p><button name='buzz' value='500'>500</button></p>"
  60. "<p><button name='buzz' value='1975'>1975</button></p>"
  61. "<p><button name='buzz' value='3000'>3000</button></p>"
  62. "<p><button name='buzz' value='8000'>8000</button></p>"
  63. "</form></body></html>";
  64.  
  65. server.printP(message);
  66. }
  67. }
  68.  
  69. void setup()
  70. {
  71.  
  72. pinMode(BUZZER_PIN, OUTPUT);
  73.  
  74.  
  75. Ethernet.begin(mac, ip);
  76.  
  77.  
  78.  
  79. webserver.setDefaultCommand(&buzzCmd);
  80.  
  81.  
  82. webserver.begin();
  83. }
  84.  
  85. void loop()
  86. {
  87.  
  88. webserver.processConnection();
  89.  
  90.  
  91. if ((++toggle & 1) && (buzzDelay > 0))
  92. {
  93. digitalWrite(BUZZER_PIN, HIGH);
  94. delayMicroseconds(buzzDelay);
  95. digitalWrite(BUZZER_PIN, LOW);
  96. }
  97. }
');