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 example'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.py from the pinned module, unchanged. Save it to your board and run it.

# FILE: SetLEDs.py
# AUTHOR: Josip Šimun Kuči @ Soldered
# 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.
# WORKS WITH: Inputronic GRID: www.soldered.com
# LAST UPDATED: 2026-05-12

from machine import I2C, Pin
from InputronicGrid import InputronicGrid
import time

# If you aren't using the Qwiic connector, manually enter your I2C pins:
# i2c = I2C(0, scl=Pin(22), sda=Pin(21))
# grid = InputronicGrid(i2c=i2c)

grid = InputronicGrid()
grid.clearLEDs()

while True:
# ── 1. Sweep individual LEDs ──────────────────────────────────────────
for row in range(4):
for col in range(4):
grid.setLED(row, col, 255, 0, 0, 255) # red
time.sleep_ms(80)
grid.setLED(row, col, 0, 255, 0, 255) # green
time.sleep_ms(80)
grid.setLED(row, col, 0, 0, 255, 255) # blue
time.sleep_ms(80)
grid.setLED(row, col, 0, 0, 0, 255) # off

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

🔗Open the complete example

Examples/SetLEDs.py at commit 36d3def

→

The example prints nothing: the result is the LED sequence above. When the board does not answer, InputronicGrid() raises an exception with the message Inputronic GRID not found. Check wiring.

Functions used​

InputronicGrid(i2c=None, address=INPUTRONIC_GRID_DEFAULT_ADDR)returns InputronicGrid

Creates the driver object and checks that the board answers. With i2c left as None it creates I2C(0, scl=Pin(22), sda=Pin(21)) on the ports the module recognises (ESP32, ESP8266 and one Soldered board), and raises an exception on a port it does not recognise.

ReturnsThe driver object. Raises an exception with 'Inputronic GRID not found. Check wiring.' when the board does not answer.

Parameters

TypeNameDescription
I2Ci2cA ready machine.I2C object. Optional.
intaddressI2C address of the board. Optional, 0x30 by default.
grid.clearLEDs()returns None

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

ReturnsNothing.

grid.setLED(row, col, r, g, b, intensity=128)returns None

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. An I2C error is ignored.

ReturnsNothing.

Parameters

TypeNameDescription
introwRow, 0 to 3.
intcolColumn, 0 to 3.
intrRed, 0 to 255.
intgGreen, 0 to 255.
intbBlue, 0 to 255.
intintensityBrightness, 0 (off) to 255 (full). Optional, 128 by default.
grid.setAllLEDs(r, g, b)returns None

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

ReturnsNothing.

Parameters

TypeNameDescription
intrRed, 0 to 255.
intgGreen, 0 to 255.
intbBlue, 0 to 255.

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 module also has setLEDMask(mask, r, g, b): bit i of the 16-bit mask lights LED i in data-line order (the numbering of setLEDByIndex(), not row by row), and every LED whose bit is clear turns off. No example uses it at this commit.