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.
- Instruction Form
- Mnemonic Form
000 E4 00FF 8000 LED 0 = orange (FF8000)
000 CD 00FF 8000 LED 0 = orange (FF8000)
| Operands | Value/Range | Remark |
|---|---|---|
| OP-00 | 00~0B | LED index (12 LEDs on board) |
| OP-01 | 00~FF | Red component |
| OP-10 | 00~FF | Green component |
| OP-11 | 00~FF | Blue 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.
- Instruction Form
- Mnemonic Form
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)
000 FZ 0010 1234 R10 = 1234
001 FZ 0011 5678 R11 = 5678
002 FZ 0012 9ABC R12 = 9ABC
003 RCD 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.
| Operands | Value/Range | Remark |
|---|---|---|
| OP-00 | 00~FF | Starting register number n (R[n]~R[n+2] = R, G, B) |
| OP-01 | 00 | Use the low 8 bits of each register |
| other | Use the high 8 bits of each register | |
| OP-10 | 00~0B | Starting LED index |
| OP-11 | 01~0C | Number of LEDs to fill |
0xE6 Set LED Mode
Set the working mode of the WS2812B LEDs.
000 E6 0002 0000 breath mode
| Operands | Value/Range | Remark |
|---|---|---|
| OP-00 | 00 | Ignored |
| OP-01 | 00 | OFF |
01 | ON — show the colors set by 0xE4/0xE5 | |
02 | Breath | |
03 | Full white | |
| OP-1 | 0000 | Ignored |
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
| Operands | Value/Range | Remark |
|---|---|---|
| OP-00 | 00~FF | Breath step count |
| OP-01 | 00~FF | Breath interval |
| OP-10 | 00~0B | Starting LED index |
| OP-11 | 00~0B | Ending 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.
| Operands | Value/Range | Remark |
|---|---|---|
| OP-00 | 00 | Natural note |
01 | Sharp | |
02 | Flat | |
| OP-01 | high 4 bits 0~2 | Octave 3/4/5 |
low 4 bits 1~7 | Note name 1=C 2=D 3=E 4=F 5=G 6=A 7=B | |
| other | Out of range: rest | |
| OP-1 | 0000~0009 | Duration slot number, see table below (16-bit whole) |
Duration slots (only slots 0~9 are valid):
| Slot | Duration | Slot | Duration |
|---|---|---|---|
| 0 | 31 ms | 5 | 250 ms |
| 1 | 62 ms | 6 | 375 ms |
| 2 | 94 ms | 7 | 500 ms |
| 3 | 125 ms | 8 | 1000 ms |
| 4 | 187 ms | 9 | 2000 ms |
A slot of 10 or above is silent.
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.
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.
- Instruction Form
- Mnemonic Form
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
000 FY 0015 0007 G4, slot 7 (500 ms)
001 FY 0011 0005 C4, slot 5 (250 ms)
002 FY 0105 0003 G#3, slot 3 (125 ms)
003 FY 0000 0003 note out of range = rest
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.
| Operands | Value/Range | Remark |
|---|---|---|
| OP-00 | 00 | Ignored |
| OP-01 | 00~FF | Line number of the first score line |
| OP-1 | 0000 | Ignored |