Skip to main content

Set the LED colours

What this example shows​

Two ways to light the grid, one after the other, in a loop:

  1. Pad by pad, row by row, each LED shows red, green and blue for 80 ms each and then turns off.
  2. All 16 LEDs together show red, green, blue and white for 400 ms each, then turn off for 300 ms.

The sketch's header comment also names a third step, a colour rotation with a bitmask, but the code at this commit does not contain it.

The example code​

This is examples/SetLEDs/SetLEDs.ino from the pinned library, unchanged.

Select Board
SetLEDs.ino
/**
**************************************************
*
* @file SetLEDs.ino
* @brief Example showing LED control on the Inputronic Grid.
*
* Demonstrates three LED control methods in sequence:
* 1. Sweep each LED individually through red, green, and blue.
* 2. Fill all 16 LEDs with a single color (solid fills).
* 3. Animate a color rotation across all 16 LEDs using a bitmask.
*
* Hardware wiring:
* - Connect Inputronic Grid to host via Qwiic / I2C
* (SDA, SCL, 3V3, GND).
*
* @authors Josip Šimun Kuči @ soldered.com
***************************************************/

#include <InputronicGrid.h>

InputronicGrid grid;

void setup()
{
Serial.begin(115200);

if (!grid.begin())
{
Serial.println("Inputronic GRID not found. Check wiring.");
while (1)
;
}

grid.clearLEDs();
}

void loop()
{
// ── 1. Sweep individual LEDs ─────────────────────────────────────────
for (uint8_t row = 0; row < 4; row++)
{
for (uint8_t col = 0; col < 4; col++)
{
grid.setLED(row, col, 255, 0, 0, 255); // red
delay(80);
grid.setLED(row, col, 0, 255, 0, 255); // green
delay(80);
grid.setLED(row, col, 0, 0, 255, 255); // blue
delay(80);
grid.setLED(row, col, 0, 0, 0, 255); // off
}
}

// ── 2. Solid fills ───────────────────────────────────────────────────
grid.setAllLEDs(255, 0, 0 ); delay(400); // red
grid.setAllLEDs(0, 255, 0 ); delay(400); // green
grid.setAllLEDs(0, 0, 255); delay(400); // blue
grid.setAllLEDs(255, 255, 255); delay(400); // white
grid.clearLEDs(); delay(300);

}

There is no serial output while it runs: the result is the LED sequence above. Only when the board does not answer does the sketch print Inputronic GRID not found. Check wiring. at 115200 baud and stop.

Functions used​

InputronicGrid(uint8_t address = INPUTRONIC_GRID_DEFAULT_ADDR)returns InputronicGrid

Creates the driver object for one GRID. The example declares it as InputronicGrid grid; with no address, so it uses the default 0x30.

ReturnsThe driver object.

Parameters

TypeNameDescription
uint8_taddressI2C address of the board. Optional, 0x30 (INPUTRONIC_GRID_DEFAULT_ADDR) by default.
grid.begin(TwoWire &wire = Wire)returns bool

Starts the I2C bus with wire.begin() and checks that the board answers on its address.

Returnstrue when the board acknowledged on the bus, false when it was not found.

Parameters

TypeNameDescription
TwoWire &wireThe I2C bus to use. Optional, Wire by default.
grid.clearLEDs()returns void

Turns all 16 LEDs off. It is the same as setAllLEDs(0, 0, 0).

ReturnsNothing.

grid.setLED(uint8_t row, uint8_t col, uint8_t r, uint8_t g, uint8_t b, uint8_t intensity)returns void

Sets the colour of the LED under one pad, by its place in the grid. Each colour value is scaled by intensity / 255 before it is sent.

ReturnsNothing.

Parameters

TypeNameDescription
uint8_trowRow, 0 to 3.
uint8_tcolColumn, 0 to 3.
uint8_trRed, 0 to 255.
uint8_tgGreen, 0 to 255.
uint8_tbBlue, 0 to 255.
uint8_tintensityBrightness, 0 (off) to 255 (full). Required in this form.
grid.setAllLEDs(uint8_t r, uint8_t g, uint8_t b)returns void

Sets all 16 LEDs to the same colour in one I2C command. The values are sent as they are, with no intensity scaling.

ReturnsNothing.

Parameters

TypeNameDescription
uint8_trRed, 0 to 255.
uint8_tgGreen, 0 to 255.
uint8_tbBlue, 0 to 255.

Always pass all six arguments to the row and column form of setLED(). With five arguments, setLED(index, r, g, b, intensity = 128) is called instead, and the first number is read as an LED index.

Putting it together​

Step 1 calls setLED() with full intensity (255) for every row and column, so the colour values reach the LED unchanged. Step 2 uses setAllLEDs(), one command for the whole grid, and clearLEDs() ends the cycle with every LED off.

To light any set of LEDs in one colour in a single command, the library also has setLEDMask(mask, r, g, b): bit i of the 16-bit mask lights LED i in data-line order (the numbering of the five-argument setLED(), not row by row), and every LED whose bit is clear turns off. No example uses it at this commit.