Controlling LED grids

Basic usage

An LED grid on a BLOCKS device can be controlled via an LEDGrid object, which can be obtained from the Block::getLEDGrid() function of a Block — see the Discovering BLOCKS section for details of how to obtain a Block object.

Using a LED grid requires a Block::Program to operate the LEDs. This program specifies some code to run on the device, and can also provide methods to be called from your application which can communicate with the code running on the device via a block of shared memory. The code which runs on the device must be specified using The LittleFoot Language, which is described in the corresponding section. However, for a very wide range of applications, the BitmapLEDProgram provided with the BLOCKS SDK is sufficient and you will not need to create your own. Using a BitmapLEDProgram to change the colour of LEDs is demonstated below.

class BlockProgramExample
// This should be called when doing the initial configuration of your application.
void setBitmapLEDProgram (Block& block)
block.setProgram (new BitmapLEDProgram (block));
// Once a BitmapLEDProgram is loaded we can use its setLED() method to change the
// colour of LEDs on the corresponding device.
void setLED (Block& block, int x, int y, LEDColour c)
if (auto program = dynamic_cast<BitmapLEDProgram*> (block.getProgram()))
program->setLED (x, y, c);

Example usage

To add this functionality to the BlockFinder example project, add the above functions to the BlockFinder class implementation. Then in the topologyChanged() callback, check if the connected Block is a Lightpad and call the above functions as shown below:

void topologyChanged() override
for (auto& block : currentTopology.blocks)
if (block->getType() == Block::lightPadBlock)
setBitmapLEDProgram (*block);
setLED (*block, 7, 7, LEDColour (0xff00ff00));

If you run the application now and connect a Lightpad, you should see a single green dot displayed in the centre of the surface.

The LED grid on a Lightpad Block

Advanced Usage

Using a custom Block::Program allows more precise control over the operation of the LEDs. The code which will actually execute on the device, returned by your overriden Block::Program::getLittleFootProgram() function, must be specified in the LittleFoot language.

Learn more about other Block methods from the following pages:

Getting touch events

Getting control button events

Controlling LED strips

Controlling control buttons

@ lightPadBlock
Lightpad block type.
Definition: juce_Block.h:45
virtual Program * getProgram() const =0
Returns a pointer to the currently loaded program.
virtual Type getType() const =0
Returns the type of this device.
A simple Program to set the colours of individual LEDs.
Definition: juce_BitmapLEDProgram.h:32
Represents an individual BLOCKS device.
Definition: juce_Block.h:32
virtual Result setProgram(Program *)=0
Sets the Program to run on this block.
A simple ARGB colour class for setting LEDs.
Definition: juce_LEDGrid.h:32