← Blog

Making my keyboard dance to music


At Yelp, twice a year, we have a 3-day company-wide hackathon where you can work on any project you want. This time, I worked on customizing my split keyboard.

My Sofle split keyboard with RGB lighting on a wooden desk

Intro

Earlier this year, I built a split keyboard (from Mechboards) because I spend a lot of time typing and using vim motions. Also, I wanted to get a custom board instead of a prebuilt one like the ones made by ZSA so I could replace the keys myself and have full control of the keyboard software. I got the Sofle, which has 58 keys instead of the 78 on a MacBook Pro keyboard. After some tinkering and advice from other split keyboard people, I ended up with this layout.

Sofle keymap, base layer

For this hackathon, I wanted to make the keyboard’s LEDs react to the audio playing on my computer. To do this, I had to learn how QMK, flashing, and sending data over USB work.

How does open source keyboard firmware work?

Firmware is the software that runs on the device itself. For a keyboard, it reads which keys are pressed and sends them to your computer over USB. Devices like keyboards, mice, and USB chargers all have a microcontroller that runs their firmware.

Fun Fact

A microcontroller is a tiny computer, with its own CPU, memory, and storage.

For my split keyboard, each half came with a Raspberry Pi Pico microcontroller. The firmware lives in flash memory, which is usually built into the microcontroller, but the Pico’s chip (the RP2040) doesn’t have any, so it’s on a separate chip. Every time the keyboard powers on, the CPU runs the firmware from the flash chip.

How the keyboard starts its firmware Plugging in the USB cable powers on the Raspberry Pi Pico. The CPU inside the RP2040 chip reads the firmware's instructions from the separate flash chip on the Pico and executes them, keeping its working data in the RP2040's RAM. Raspberry Pi Pico RP2040 USB plugged in CPU runs firmware Flash chip stores firmware RAM working data 1. power on 2. read firmware 3. execute

Custom keyboards let you flash your own firmware, meaning I can erase the flash memory and write whatever program I want to it.

Flashing any program

You could flash a program that just runs printf("hello world!") and exits (but you wouldn’t see the output anywhere and the keyboard would be useless).

This is where Quantum Mechanical Keyboard (QMK) comes in. QMK is open source keyboard firmware that supports thousands of keyboards. Its main use is giving you full control over what each key does, but it can do more than that. For this hackathon, I wanted it to read data from my computer and update the LEDs 60 times a second.

Building KeyGlow

Using Claude, I vibecoded a lightweight Swift app that listens to system audio and runs a Fast Fourier Transform (FFT) on it to split the sound into frequency bands, like the bars on a music visualizer. It sends those levels over USB to the left half of the keyboard, which sends them to the right half over the split cable.

From system audio to keyboard LEDs On the Mac, the KeyGlow app listens to system audio and runs an FFT to split it into frequency bands, then sends the band levels over USB to the left half of the keyboard. Both halves run the same firmware loop: scan_keys(), then, on the left half, read_usb() and send_to_right_half(), or on the right half, read_from_left_half(), then update_leds(). The left half sends the levels to the right half over the split cable. The right half isn't on USB, so it loops about twice as fast. MacBook System audio whatever's playing KeyGlow app Swift · FFT into bands USB · band levels Left half while (true) { scan_keys(); if (is_left_half()) { read_usb(); send_to_right_half(); } else { read_from_left_half(); } update_leds(); } Right half while (true) { scan_keys(); if (is_left_half()) { read_usb(); send_to_right_half(); } else { read_from_left_half(); } update_leds(); } split cable · levels

On each half, the firmware is basically a while (true) loop that scans the keys, checks for packets that start with K (0x4B), and updates the LEDs. The right half isn’t plugged in over USB, so it skips the USB part and loops faster. My firmware, including KeyGlow, is on GitHub.

Displaying Album Art

Each half of the keyboard also has a small 135×240 LCD panel that can display anything. With KeyGlow working smoothly, I wanted to make use of the display. Rendering the song name, artist, and album cover seemed cool. Fortunately, Apple Music supports AppleScript, which lets you get the current song’s name, artist, and album art. I created a new function in KeyGlow that gets the image, shrinks it to 120×120 pixels, and sends it over the USB cable. The firmware then renders it on the left display.