-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add own functionality
This page is intended for those wishing to modify the WLED code to add their own functionality.
Programming is done in the Arduino IDE. There is a special file, wled06_usermod.ino
, to write your own code.
(however, if you think your code may be relevant to many users, feel free to code it in directly and open a pull request)
This file has three empty methods:
-
userBeginPreConnection()
is called after loading settings but before connecting to WiFi. Use it to load custom settings or to specify own server pages with theserver.on()
method. -
userBegin()
is the main initialization. Use it to start own interfaces (IR, UDP ports, Websockets, GPIOs,...). -
userLoop()
is called by the mainloop()
function.
If you know what you're doing, you may choose to change the value of any global variable declared in wled00.ino
.
However, for basic color and brightness changes, these are the most important:
Variable Name | Type | Purpose |
---|---|---|
bri | byte (0-255) | Master Brightness (0 is off, 255 is maximum) |
col[0] | byte (0-255) | Red color value |
col[1] | byte (0-255) | Green color value |
col[2] | byte (0-255) | Blue color value |
white | byte (0-255) | White color value |
After updating the color, you must call the colorUpdated(int)
method. If you want to send a notification with the new color to other ESPs, use colorUpdated(1)
, otherwise colorUpdated(5)
.
If you'd just like a simple modification that requires timing (like sending a request every 2 seconds), please never use the delay()
function in your userLoop()
! It will block everything else and WLED will become unresponsive and effects won't work! Instead, try this instead:
long lastTime = 0;
int delayMs = 2000; //we want to do something every 2 seconds
void userLoop()
{
if (millis()-lastTime > delayMs)
{
lastTime = millis();
//do something you want to do every 2 seconds
}
}
You can use Segments from your code to set different parts of the strip to different colors or effects.
This can be very useful for highly customized installations, clocks, ...
To set a segment, use strip.setSegment(id, start, stop);
, where id is the segment ID, start is the first LED of the segment and stop is the LED after the last one in the segment.
To edit the configuration of a segment, use:
WS2812FX::Segment& seg = strip.getSegment(id);
//set color (i=0 is primary, i=1 secondary i=2 tertiary)
seg.colors[i] = ((myWhite << 24) | ((myRed&0xFF) << 16) | ((myGreen&0xFF) << 8) | ((myBlue&0xFF)));
//set effect config
seg.mode = myFxI;
seg.speed = mySpeed;
seg.intensity = myIntensity;
seg.palette = myPaletteId;
Keep in mind that this will not cause interface updates as of 0.8.6. For that, you still need to use 'colorUpdated(1)'
TBD
- List of effects and palettes
- Macros & Button
- Multi strip
- Presets
- Segments
- Webserver sitemap
- Control a relay
- Blynk
- DMX Output
- E1.31 (DMX) / Art-Net
- UDP Realtime / tpm2.net
- HTTP Request API
- Infrared
- JSON API
- MQTT
- Philips hue sync
- WebSocket
- WLED UDP sync