Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "SPI.h"
- #include "Ethernet.h"
- #include "WebServer.h"
- static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
- static uint8_t ip[] = { 192, 168, 0, 50 };
- #define PREFIX "/buzz"
- WebServer webserver(PREFIX, 80);
- #define BUZZER_PIN 3
- int buzzDelay = 0;
- char toggle = 0;
- void buzzCmd(WebServer &server, WebServer::ConnectionType type, char *url_tail, bool tail_complete)
- {
- if (type == WebServer::POST)
- {
- bool repeat;
- char name[16], value[16];
- do
- {
- repeat = server.readPOSTparam(name, 16, value, 16);
- if (strcmp(name, "buzz") == 0)
- {
- buzzDelay = strtoul(value, NULL, 10);
- }
- } while (repeat);
- server.httpSeeOther(PREFIX);
- return;
- }
- server.httpSuccess();
- if (type == WebServer::GET)
- {
- P(message) =
- "<html><head><title>test buzzer computermuseo</title>"
- "<body>"
- "<h1>testa il tuo buzzer</h1>"
- "<form action='/buzz' method='POST'>"
- "<p><button name='buzz' value='0'>Turn if Off!</button></p>"
- "<p><button name='buzz' value='500'>500</button></p>"
- "<p><button name='buzz' value='1975'>1975</button></p>"
- "<p><button name='buzz' value='3000'>3000</button></p>"
- "<p><button name='buzz' value='8000'>8000</button></p>"
- "</form></body></html>";
- server.printP(message);
- }
- }
- void setup()
- {
- pinMode(BUZZER_PIN, OUTPUT);
- Ethernet.begin(mac, ip);
- webserver.setDefaultCommand(&buzzCmd);
- webserver.begin();
- }
- void loop()
- {
- webserver.processConnection();
- if ((++toggle & 1) && (buzzDelay > 0))
- {
- digitalWrite(BUZZER_PIN, HIGH);
- delayMicroseconds(buzzDelay);
- digitalWrite(BUZZER_PIN, LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement