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));
}
};

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);
}
}
}

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

Block::developerControlBlock
@ developerControlBlock
Developer control block type.
Definition: juce_Block.h:48
Block::liveBlock
@ liveBlock
Live control block type.
Definition: juce_Block.h:46
Block::getType
virtual Type getType() const =0
Returns the type of this device.
Block::loopBlock
@ loopBlock
Loop control block type.
Definition: juce_Block.h:47
Block::getLEDRow
virtual LEDRow * getLEDRow()=0
If this block has a row of LEDs, this will return an object to control it.
Block
Represents an individual BLOCKS device.
Definition: juce_Block.h:32
LEDColour
A simple ARGB colour class for setting LEDs.
Definition: juce_LEDGrid.h:32
Block::touchBlock
@ touchBlock
Touch control block type.
Definition: juce_Block.h:49