The BLOCKS SDK
Controlling LED strips

Control Blocks have a strip of LEDs which can be controlled via an LEDRow object.

A pointer to an LEDRow object can be obtained from the Block::getLEDRow() method of a Block — see the Discovering BLOCKS section for details of how to obtain a Block object. Once you have an LEDRow there are a few functions that you can use to interact with the strip of LEDs on a device. A code snippet showing how to turn the whole strip of LEDs on a Block yellow is shown below.

class BlockLEDExample
{
public:
void setWholeLEDRowYellow (Block& block)
{
if (auto ledRow = block.getLEDRow())
for (int i = 0; i < ledRow->getNumLEDs(); ++i)
ledRow->setLEDColour (i, LEDColour (0xffffff00));
}
};
Represents an individual BLOCKS device.
Definition: roli_Block.h:31
virtual LEDRow * getLEDRow()=0
If this block has a row of LEDs, this will return an object to control it.
A simple ARGB colour class for setting LEDs.
Definition: roli_LEDGrid.h:31

Example usage

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:

void topologyChanged() override
{
//...
for (auto& block : currentTopology.blocks)
{
//...
if (block->getType() == Block::liveBlock || block->getType() == Block::loopBlock
{
setWholeLEDRowYellow (*block);
}
}
}
@ loopBlock
Loop control block type.
Definition: roli_Block.h:45
@ liveBlock
Live control block type.
Definition: roli_Block.h:44
@ touchBlock
Touch control block type.
Definition: roli_Block.h:47
@ developerControlBlock
Developer control block type.
Definition: roli_Block.h:46
virtual Type getType() const =0
Returns the type of this device.

If you run the application now and connect a Control Block, you should see the LEDs in the strip turn yellow.

The LED strip on a Control Block

Learn more about other Block methods from the following pages:

Getting touch events

Getting control button events

Controlling LED grids

Controlling control buttons