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 iconic 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 should 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“.
This ended up being very easy to implement 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 array of white LEDs and a handy enclosure. He also wired up a simple transistor circuit on a scrap of perfboard so the Arduino Pro Mini could control all the LEDs from a single GPIO pin. Combined with a long USB cable to power it, and he’s got a perfect 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.
Why would anyone feel shame for reusing good code?
It’s not like code gets stale or grows mold.
*looks at Basic code full of Gotos*
I mean, if it’s GOOD code, then sure keep using it.
But if you’re using the same old janky code for years just because you can’t be bothered to update it, then that’s a problem. One would hope your skills are improving with time, so if there’s really no difference in your style or efficiency in 10 years…
Wow. I always thought that was a bad backlight in my monitor…
I imagine for some that flicker would be hard on the eyes.
Just in time for Halloween. This’ll save me some work. I’m going to add a button to cycle styles though because that sounds easier than reflashing each time I might want to change it.
Also, since it uses text, I may have to see what various curse words look like in flicker.
This seems more like Doom3 lights.
That good old bad fluorescent lamp flicker is going extict.
LEDs have completely other failure modes.
I wonder what future horror movies will use.
I always cringe when todays horror movies/games use the beam of an old incandescent flashlight.
Honestly, guys? Even my humble key chain light has 1000 Lumens. And that’s not even the brightest one.
I’ve seen LED streetlights which look like they’re trying to be disco strobes or send morse code. It’s a shame how much material goes into these things in the name of saving energy when they don’t last very long.
The best outdoor lighting solution is none at all, but second to that is the fluorescent induction lamp. There’s nothing to wear other than the phosphor (which should last 20 years or more if not overdriven), and it doesn’t require a giant heat sink.
> [Rodrigo] simply had to assign each letter in the string a numerical value between 0 and 255 using map
Hm, why not just use the ASCII code of the letter, subtract the ASCII code for ‘a’ and multiply by 256/26?
Just multiply it by 10, that’s close enough.
This just gives me a headache……not the article the flickering lights. 8)
I know Arduinos are cheap these days, and would give you more control if you actually want that control… but that’s the long way around the barn.
The traditional way to create an erratically flickering light effect was just a fluorescent starter. Starters were traditionally just a thermostat and a neon bulb in series; the bulb would heat the thermostat, it would turn off, the system would cool, and this on/off behavior run through an inductor provided the surge needed to initially ionize the gas in the tube, repeating until (and after) the arc caught. Putting that erratically-repeating cycle in series with an incandescent bulb instead produced a nice irregular flicker; the hysteresis as the bulb warmed up and cooled off would cause each flash to vary in brightness too. The result looked very much like what you’d expect from a loose connection (without the hazards thereof); you could get some control of the rate and brightness by picking the bulb wattage and/or putting it on a dimmer.
If you’ve seen a flickering light in a haunted house or on stage, this is probably how they built it.
Used as flickering light in a Halloween prop. Music from Doom.
https://saanlima.com/videos/IMG_6264.MOV