Skip to main content

LED & Music

Instructions in this category drive the WS2812B full-color LEDs and the sound generator.

The WS2812B module can be enabled with the WS2812B Switch 0xCB (automatic since the 2026-09 firmware), and the MIDI player requires Playtune to be activated with the Playtune Switch 0xD0.

0xE4 Set Color of One LED (CD)​

Set the color of a single WS2812B LED by its index. Each color component is an 8-bit value (0~255). If the current mode is OFF, it is switched to ON automatically.

000  E4  00FF  8000    LED 0 = orange (FF8000)
info
OperandsValue/RangeRemark
OP-0000~0BLED index (12 LEDs on board)
OP-0100~FFRed component
OP-1000~FFGreen component
OP-1100~FFBlue component

0xE5 Set LED Colors from Registers (RCD)​

Fill one or more consecutive LEDs with a single color taken from three consecutive registers R[n]~R[n+2] (R, G, B). OP-01 selects which byte of each register is used: 00 = low 8 bits, any other value = high 8 bits. If the current mode is OFF, it is switched to ON automatically.

000  10  0010  1234    R10 = 1234
001 10 0011 5678 R11 = 5678
002 10 0012 9ABC R12 = 9ABC
003 E5 1001 0006 LED 0~5 = color 12569A (high bytes)

With OP-01 = 01, the high bytes of R10~R12 (12, 56, 9A) form the color 12569A; with OP-01 = 00, the low bytes would form 3478BC.

info
OperandsValue/RangeRemark
OP-0000~FFStarting register number n (R[n]~R[n+2] = R, G, B)
OP-0100Use the low 8 bits of each register
otherUse the high 8 bits of each register
OP-1000~0BStarting LED index
OP-1101~0CNumber of LEDs to fill

0xE6 Set LED Mode​

Set the working mode of the WS2812B LEDs.

000  E6  0002  0000    breath mode
info
OperandsValue/RangeRemark
OP-0000Ignored
OP-0100OFF
01ON — show the colors set by 0xE4/0xE5
02Breath
03Full white
OP-10000Ignored

0xE7 Set Breath Parameters​

Configure the breath light effect. The mode must be set to breath (0xE6 with OP-01 = 02) beforehand.

000  E6  0002  0000    switch to breath mode first
001 E7 05C0 000B 5 steps, interval C0, LEDs 0~11
info
OperandsValue/RangeRemark
OP-0000~FFBreath step count
OP-0100~FFBreath interval
OP-1000~0BStarting LED index
OP-1100~0BEnding LED index

0xE8 Play a Tone (FY)​

Play one note on the buzzer. OP-0 describes the pitch, OP-1 the duration.

The note byte (OP-01) combines the octave in its high 4 bits (02) and the note name in its low 4 bits (17 = C D E F G A B). Values out of range play a rest. Octave code 0/1/2 corresponds to octave 3/4/5 — for example 11 = C4, 15 = G4 and 05 = G3.

info
OperandsValue/RangeRemark
OP-0000Natural note
01Sharp
02Flat
OP-01high 4 bits 0~2Octave 3/4/5
low 4 bits 1~7Note name 1=C 2=D 3=E 4=F 5=G 6=A 7=B
otherOut of range: rest
OP-10000~0009Duration slot number, see table below (16-bit whole)

Duration slots (only slots 0~9 are valid):

SlotDurationSlotDuration
031 ms5250 ms
162 ms6375 ms
294 ms7500 ms
3125 ms81000 ms
4187 ms92000 ms

A slot of 10 or above is silent.

tip

For classroom melodies, slots 3 / 5 / 7 (125 / 250 / 500 ms) cover most rhythm patterns — roughly sixteenth, eighth and quarter notes at a moderate tempo.

caution

The slot number must be written into the low byte of OP-1 (P11); the high byte P10 always stays 00. Putting the slot into the high byte — e.g. E8 0015 0500 — makes the 16-bit value 1280, which is ≥ 10, and the note is silent.

000  E8  0015  0007    G4, slot 7 (500 ms)
001 E8 0011 0005 C4, slot 5 (250 ms)
002 E8 0105 0003 G#3, slot 3 (125 ms)
003 E8 0000 0003 note out of range = rest
note

While a note plays, the melody generator temporarily occupies the buzzer; when playback finishes, the on-board PWM (PB3) is available again.

0xFE Play MIDI​

Play a score through the Playtune engine. Playtune must be activated with the Playtune Switch 0xD0 beforehand.

000  D0  0000  0001    activate Playtune first
001 FE 0000 0008 play the score starting at line 008
002 0F 0000 0000 program end

Lines from 008 onwards store the score data. They are not executed as instructions: playback is blocking — the program waits until the tune finishes — and the program counter skips the score lines automatically.

info
OperandsValue/RangeRemark
OP-0000Ignored
OP-0100~FFLine number of the first score line
OP-10000Ignored