If you ever feel a pang of shame because you’ve been reusing the same snippets of code in your projects for years, don’t. even the big names do it, as evidenced by the fact that code written to govern flickering lights back in 1996 for Quake is still being used in AAA titles like 2020’s Half-Life: Alyx. In honor of this renowned example of digital buck-passing, [Rodrigo Feliciano] thought he’d port the code in question over to the Arduino and recreate the effect in real-life.
Since the Quake engine has been released under the GPLv2, it’s easy to pull up the relevant section of the code to see how the lighting was configured. Interestingly, lighting patterns were implemented as strings, where the letters from a to z referenced how bright the light ought to appear. So for example, a strobe light that goes between minimum and maximum brightness would be written as “aaaaaaaazzzzzzzz”, while a flickering light could be represented with the string “nmonqnmomnmomomno“.
An emergency light offered the LEDs and enclosure.
This ended up being very easy to execute on the Arduino in just a few lines, as [Rodrigo] simply had to assign each letter in the string a numerical value between 0 and 255 using map, and then use the resulting number to set the LED brightness with analogWrite.
With the code written, [Rodrigo] then had to put the hardware together. He stripped down a basic emergency light to get an range of white LEDs and a useful enclosure. He also wired up a easy transistor circuit on a scrap of perfboard so the Arduino pro small could control all the LEDs from a single GPIO pin. combined with a long USB cable television to power it, and he’s got a ideal desk accessory for late-night gaming sessions.
In the video below you can see the final result, which [Rodrigo] has even synced up to footage from the classic 1996 shooter. The light makes for an interesting conversation piece, but we think the logical next step is to work this technique into an ambilight-like system to really make it feel like you’re wandering down those dimly lit corridors.