Files
LEDUsermod/usermod.cpp
2023-12-26 18:21:58 +01:00

48 lines
1.3 KiB
C++

#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();
}
}