From ae76fd7bff69af704f39a7952218261413105bf4 Mon Sep 17 00:00:00 2001 From: rogo Date: Tue, 26 Dec 2023 18:21:58 +0100 Subject: [PATCH] init --- usermod.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 usermod.cpp diff --git a/usermod.cpp b/usermod.cpp new file mode 100644 index 0000000..b541e0b --- /dev/null +++ b/usermod.cpp @@ -0,0 +1,48 @@ +#include "wled.h" +/* + * This v1 usermod file allows you to add own functionality to WLED more easily + * See: https://github.com/Aircoookie/WLED/wiki/Add-own-functionality + * EEPROM bytes 2750+ are reserved for your custom use case. (if you extend #define EEPSIZE in const.h) + * If you just need 8 bytes, use 2551-2559 (you do not need to increase EEPSIZE) + * + * Consider the v2 usermod API if you need a more advanced feature set! + */ + +//Use userVar0 and userVar1 (API calls &U0=,&U1=, uint16_t) +long last = 0; // update timer +byte lastBri = 0; + +byte readPoti() +{ + int read = analogRead(A0); + return map(read, 0, 1023, 0, 255); +} + +//gets called once at boot. Do all initialization that doesn't depend on network here +void userSetup() +{ + pinMode(A0, INPUT); + last = millis(); + + bri = 0; + colorUpdated(CALL_MODE_DIRECT_CHANGE); +} + +//gets called every time WiFi is (re-)connected. Initialize own network interfaces here +void userConnected() +{ } + +//loop. You can use "if (WLED_CONNECTED)" to check for successful connection +void userLoop() +{ + if (millis() - last > 500) { + byte val = readPoti(); + + if (abs(val-lastBri) > 2 ) { + bri = val; + lastBri = val; + colorUpdated(CALL_MODE_DIRECT_CHANGE); + } + last = millis(); + } +} \ No newline at end of file