Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <WiFiManager.h>
- #include <HTTPClient.h>
- #define BUTTONPIN 23
- #define DEBOUNCEMS 15
- String toggleURL = "http://led.web.lan/toggleleds.php?state=";
- unsigned short buttonState = HIGH, lastButtonState = HIGH;
- void sendToggleMessage(bool state) {
- char webMsg[255] = "";
- strcat(webMsg, toggleURL.c_str());
- strcat(webMsg, (state) ? "true" : "false");
- HTTPClient http;
- http.begin(webMsg);
- http.GET();
- http.end();
- }
- void setup() {
- Serial.begin(115200);
- pinMode(BUTTONPIN, INPUT_PULLUP);
- Serial.println("MAC Address: " + WiFi.macAddress());
- WiFiManager wifiManager;
- wifiManager.autoConnect("ToggleLEDs");
- }
- unsigned long lastDebounceTime = 0;
- bool toggleState = false;
- bool debouncing = false;
- void loop() {
- unsigned short buttonCheck = digitalRead(BUTTONPIN);
- if ( buttonCheck != lastButtonState ) {
- debouncing = true;
- lastDebounceTime = millis();
- }
- if ( debouncing && (millis() >= (lastDebounceTime + DEBOUNCEMS)) ) {
- debouncing = false;
- if ( buttonCheck != buttonState ) {
- buttonState = buttonCheck;
- if ( buttonState == LOW ) {
- toggleState = !toggleState;
- sendToggleMessage(toggleState);
- }
- }
- }
- lastButtonState = buttonCheck;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement