"Lights Out" with a keyboard

30 May 2023

C  Hardware 

A while back I was idly thinking about the old Lights out game, and wondering if my kid would be interested in such a thing. Digging around on eBay found various slightly knacked versions of it in the £50+ range, which didn't feel worth it. I started down a bit of a rabbit hole for a while of going "hey, could I build this like a keyboard?" and reading keyboard building tutorials. This was tempting (mostly in a "find an excuse to finally have something I could test out PCBWay with"), but felt like a lot of effort that I wasn't willing to put in, so I parked it. I briefly un-parked it when I found the Adafruit NeoKey Ortho board but, again it didn't quite unpark my thinking.

Except then Ben Jemmett posted about hardware projects he should finish, I mentioned this keyboard idea and then Tony Finch was a terrible enabler finding me a much easier route to making this....

So, here's the core insight. Previously, I'd been thinking of this as a "keyboard + microcontroller" project, and given no-one actually sells that sort of thing as a unit (ok, there's probably counter-examples, but I hadn't found one I liked), I'd have to build one, and although I can do some hardware stuff, I'm more of a software person, and so this was a hard enough project I was ignoring it. Except this isn't quite true, as modern keyboards that support things like QMK are more than capable enough for me to just write Lights Out directly as a funky keyboard layout.

The "keymap" is available as a Pull Request for QMK (which should get merged eventually), and looks like the following.

How it works is that when you plug it into a USB-C power source (which can be a computer, but doesn't have to be), it generates a Lights Out game that can be solved in one move (by the simple method of doing one move, because the moves are symmetric). If you solve that, it shows the pretty rainbow pattern (QMK's built-in "rainbow swirl"). If you then push any key, it makes you a new game that needs two moves to solve. If you solve that, the next game needs three moves, and so on until you get bored or can't solve it. Note that sometimes it picks a combination of moves that results in some game being a lot easier than it should be, which I might fix eventually. It explicitly doesn't actually work as a keyboard, as in it outputs no keycodes when you push keys.

I did also have a brief go at trying to do this for Rust with the smart-leds work, but I'd have to fix some fairly hairy timer issues which I've filed under "really hard without a dev board", and quite frankly QMK and a little bit of C was a lot easier.

Sadly kiddo was only slightly interested in it, and mostly as a "hammer the buttons" thing, but I might try again in a couple of years. I will also note that the cost of this for the keyboard plus some see-through keycaps ended up being about £50 after tax and shipping, so I could have probably got a real one cheaper, but this was way more fun :) Although, if someone wanted to do a Kickstarter to build a proper version of this, they could probably do it a lot cheaper.

Previously: Paracrine Next: Migrating from PostgreSQL to CockroachDB