init
This commit is contained in:
48
usermod.cpp
Normal file
48
usermod.cpp
Normal file
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user