In addition to sending button pressed and button released events, ControlButton objects can allow your application code to change the colour of the LED behind the corresponding physical button on a BLOCKS device.
An array of pointers to the available ControlButton objects can be obtained from the Block::getButtons() method of a Block — see the Discovering BLOCKS section for details of how to obtain a Block object. Once you have a ControlButton, the functions involving the LED are ControlButton::hasLight() and ControlButton::setLightColour(), which are descriptively named. A code snippet showing how to turn all the available buttons of a Block red is shown below.
To add this functionality to the BlockFinder example project, add the above function to the BlockFinder class implementation. Then in the topologyChanged()
callback, check if the connected Block is a Control Block and call the above function as shown below:
If you run the application now and connect a Control Block, you should see the control buttons turn red.
Learn more about other Block methods from the following pages: