LED
A round lamp. The sketch publishes on or off with virtualWrite. The dashboard does not send a click back to the device.
Set it up on the server
- Sign in to the Box IO dashboard and open the project that uses this device key.
- Turn on Edit.
- In Edit, add LED.
- Set Virtual pin to
0so it matchesV0in the sketch. - Set Label, Color on, and Color off. Color on is the lit color.
- Save the layout, then open Live.
- Flash the sketch below with the same device key, host, and port
5923. KeepBoxIO.run()inloop().
Properties
Sketch values are always strings, including numbers: BoxIO.setProperty(V2, "max", "200").
| Property | Where to set it | Format | Example | Effect |
|---|---|---|---|---|
colorOn | Dashboard or sketch | #RRGGBB | #ff5d73 | Lit color. |
colorOff | Dashboard or sketch | #RRGGBB | #1a2333 | Unlit color. The lamp stays dimmer while off. |
color | Sketch | #RRGGBB | #ff5d73 | Alias for the lit color when colorOn is not set. |
label | Dashboard or sketch | Plain text | Pump | Caption above the widget. On a round or oval button this is the caption, not the word on the button face. |
hideLabel | Dashboard | On or off | checked | Hides the caption. Button face text, meter numbers, and label text stay visible. |
fontSize | Dashboard | Whole number 8 to 160, or blank for automatic size | 28 | Text size in pixels inside the widget. |
opacity | Dashboard | 10% to 100% | 70% | Lets an overlapping widget show through. 100% is solid. |
Formatting
- The pin value is text. These are off: empty,
0,false,off,no(any capitalisation). Every other value is on, including1andtrue. - Colors are
#plus 6 hex digits, for example#ff5d73.
Sketch
Paste the device key over bx_paste_your_device_key_here. Wi-Fi boards include BoxIOEsp32.h. Ethernet boards use the same calls with an EthernetClient.
#define BOXIO_AUTH "bx_paste_your_device_key_here"
#define WIFI_SSID "your-ssid"
#define WIFI_PASS "your-password"
#define BOXIO_HOST "localhost"
#define BOXIO_PORT 5923
#include <BoxIOEsp32.h>
void setup() {
BoxIO.begin(BOXIO_AUTH, WIFI_SSID, WIFI_PASS, BOXIO_HOST, BOXIO_PORT);
BoxIO.setProperty(V0, "label", "LED Lab");
BoxIO.setProperty(V0, "colorOn", "#ff5d73");
BoxIO.setProperty(V0, "colorOff", "#1a2333");
BoxIO.virtualWrite(V0, 1);
}
void loop() {
BoxIO.run();
static uint32_t last = 0;
if (millis() - last < 1000) return;
last = millis();
static int on = 0;
on = !on;
BoxIO.virtualWrite(V0, on);
}
What you should see
The lamp lights when the pin is on and dims when it is off. A later setProperty from the sketch replaces a color you typed on the dashboard until you edit that color again.