Configure LEDs
The Behavior board drives two kinds of light output: two standard current-controlled LEDs on the L0 and L1 terminals and up to two WS2812-type addressable RGB LEDs on the RGB connector. Refer to the connections article to set up the LED on L0 or the RGB connector, which we will use for the rest of these examples.
This article covers configuring LED drive current, setting RGB colors, and turning on both kinds of LED output in Bonsai.
The complete workflow is shown below:
Warning
The RGB section has not been tested as I do not have the hardware yet. There is also supposedly a regression introduced in firmware 3.4 which prevents the RgbAll, Rgb0, and Rgb1 registers from updating the LED colors — the LEDs stay at their default colors (RGB0 green, RGB1 blue).
Configure LED Current
The L0 and L1 outputs drive standard single-color LEDs with a configurable constant current, so no series resistor is needed. Each output has a working current register (Led0Current, 2 – 100 mA) and a protection limit (Led0MaxCurrent, 5 – 100 mA); writes above the limit are rejected by the device.
- Insert a
KeyDownoperator and set theFilterproperty toA. - Insert a
CreateMessageoperator and configure the following properties:Payload- SelectLed0MaxCurrentPayload.Led0MaxCurrent- Set the maximum allowed current according to the rating of the LED in mA (e.g. 20).
- Insert a
MulticastSubjectoperator namedBehavior Commands. - Insert a
CreateMessageoperator and configure the following properties:Payload- SelectLed0CurrentPayload.Led0Current- Set the working current in mA (e.g. 10).
- Insert a
MulticastSubjectoperator namedBehavior Commands.
Run the workflow and press A to configure the LED 0 drive current, then switch the output on as shown in the next section.
Turn LEDs On and Off
Once the drive current is configured, the L0 and L1 outputs are switched like any other digital output, for instance through the OutputSet and OutputClear registers:
- Insert a
KeyDownoperator and set theFilterproperty toS. - Insert a
CreateMessageoperator and configure the following properties:Payload- SelectOutputSetPayload.OutputSet- SelectLed0.
- Insert a
MulticastSubjectoperator namedBehavior Commands.
In a separate branch:
- Insert a
KeyDownoperator and set theFilterproperty toD. - Insert a
CreateMessageoperator and configure the following properties:Payload- SelectOutputClearPayload.OutputClear- SelectLed0.
- Insert a
MulticastSubjectoperator namedBehavior Commands.
Run the workflow, then press S to light the LED and D to turn it off. See Control Digital Outputs for other methods to control the LED.
Set RGB Colors
The RGB connector drives WS2812-type addressable LEDs — often sold as "NeoPixel" LEDs, rings, or strips. The two LEDs form a serial chain on a single data line: RGB0 is the first LED in the chain and RGB1 the second. Plain and analog RGB LEDs have no data input and do not work on this connector; drive those from the L0/L1 outputs instead.
The RgbAll register writes the color of both RGB LEDs in one command. Each channel takes an intensity from 0 to 255. To write one LED at a time, use Rgb0 or Rgb1 instead.
- Insert a
KeyDownoperator and set theFilterproperty toF. - Insert a
CreateMessageoperator and configure the following properties:Payload- SelectRgbAllPayload.Red0- Set to 255 to make RGB0 red.Blue1- Set to 255 to make RGB1 blue.
- Insert a
MulticastSubjectoperator namedBehavior Commands.
Run the workflow and press F to load the colors. If the LEDs are currently on, the new colors take effect immediately.
Turn RGB LEDs On and Off
The RGB LEDs are switched like any other digital output, for instance through the OutputSet and OutputClear registers:
- Insert a
KeyDownoperator and set theFilterproperty toG. - Insert a
CreateMessageoperator and configure the following properties:Payload- SelectOutputSetPayload.OutputSet- SelectRgb0andRgb1.
- Insert a
MulticastSubjectoperator namedBehavior Commands.
In a separate branch:
- Insert a
KeyDownoperator and set theFilterproperty toH. - Insert a
CreateMessageoperator and configure the following properties:Payload- SelectOutputClearPayload.OutputClear- SelectRgb0andRgb1.
- Insert a
MulticastSubjectoperator namedBehavior Commands.
Run the workflow, then press G to light both RGB LEDs and H to turn them off. See Control Digital Outputs for other methods to control the LED.
Last updated with:
Hardware v2.1
Firmware v3.3
Bonsai Package v0.2