RGB LED Button
Last updated
Was this helpful?
Last updated
Was this helpful?
You know how to get a handle on the RGB LED button connected to your computer
You can set the color of the LED, turn it on and off, and make it blink, and use the functionality of the button itself.
We can make our application more interactive and get input from a user with the . In this article, we assume you have successfully initialized the devices with the , and you stored all connected devices on a global variable devices
. We also declared a global variable button
.
Next, we need to know the device identifier of the RGB LED Button, which is 282:
Now that we have a reference to the button on the variable button
, we can use that variable to call the button's LED functions. These are the same as for the .
With setColor()
we can turn the button's LED on and specify the color of the light. We define the color using the RGB notation:
We can turn the button's LED off (black) at any time with the shortcut function off()
:
Similar to setting the color, we can use blink()
to make the button's LED blink at a given frequency:
The more important functionality of the button is to react to the event that someone pressed the button. We can achieve this using the listener button and a callback function, as we do with sensors:
Within the callback function, we can distinguish the two events "PRESSED" or "RELEASED":