I’ve finally discovered how to implement a lava lamp effect on an array of tri-colored LEDs using noise.

Clive 'Max' Maxfield

December 14, 2021

7 Min Read
Clive feature_28.jpeg
Clive "Max" Maxfield

When I was young and foolish -- as opposed to my current state of being, in which one of these descriptors is surplus to requirements -- I regarded most forms of noise as being my enemy. So, you can only imagine my surprise to discover just how useful noise can be in the right circumstances.

Actually, we should probably qualify this by noting that we’re predominantly talking about noise in electronic systems and using noise to create audible and visual effects, because different scientific and engineering disciplines have different definitions as to what noise is. For example, the term communication noise, which refers to influences on effective communication that affect the interpretation of conversations, includes psychological noise, physiological noise, environmental noise, physical noise, and semantic noise.

When it comes to electronics and physics, including audio engineering and many other fields, we may refer to noise as having different colors, such as “white noise” and “pink noise,” where these appellations refer to the power spectrum of the noise signal (white noise has a flat frequency spectrum when plotted as a linear function of frequency, while the frequency spectrum of pink noise is linear in a logarithmic scale). Just to add to the fun and frivolity, there are also red, green, blue, violet, gray, brown (short for Brownian), black, and Gaussian forms of noise.

Different colors of noise have different properties. As audio signals, for example, white noise might sound like rain or rustling leaves or the static on an old cathode ray tube (CRT) television set that’s not tuned to a broadcasting channel, while pink noise is a little more structured, like the sound of waves crashing on a beach or the “chuff chuff chuff” sound of an old-fashioned steam engine. By comparison, when different colors of noise are applied to images, they will result in visibly different textures.

fig-01.jpg

Have you heard the terms “dither” and “dithering” in the context of engineering? When we take a continuously varying signal in the analog domain and convert it into an equivalent in the digital realm, we use a process called “quantization” to constrain the signal to a finite number of discrete states known as “quanta.” As part of this, we introduce errors called quantization errors.

Well, dithering refers to intentionally superimposing a noise signal on top of the main signal of interest prior to quantization to randomize any quantization errors. In the case of images, this can prevent large-scale patterns such as banding. In the case of an analog-to-digital converter (ADC), adding dither can effectively increase the resolution of the converter. Suppose we have an 8-bit ADC, for example, then if we superimpose a noise signal with a peak-to-peak amplitude equal to one least-significant bit (LSB), over-sample the input at 4X the original sampling rate, and then apply a low-pass filter to the output of the ADC (the simplest low pass filter is to average the samples), the result is to make the 8-bit ADC act as a 9-bit ADC.

One thing I found to be really interesting is that one of the earliest applications of dither of which we are aware came in WWII. At that time, airplane bombers used mechanical computers (boxes filled with hundreds of gears and cogs) to perform navigation and bomb trajectory calculations. Curiously, these computers performed their calculations more accurately when the planes were in the air with their engines running than when they were on the ground with their engines off. It turned out that the vibration of the aircraft reduced error caused by sticky moving parts. Instead of moving in short jerks, the added vibration caused them to move more continuously. This discovery drove the engineers to build small vibrating motors into the computers. The vibration they introduced was called “dither” from the Middle English verb "didderen," meaning "to tremble."

In fact, dithering finds all sorts of applications. In the case of hydraulic-power systems where fluid pressure is used to control the position of a servo valve, for example, introducing a small amount of dither into the servo-valve control loop can prevent jerks that affect system accuracy. Another example is found in switched-mode power supplies, where applying dither to the pulse-width modulation (PWM) controller’s switching frequency can significantly reduce the peak amplitudes of the spectral components in the electromagnetic interference (EMI) generated by the controller.

But none of this is what I wanted to talk about LOL. My recent interest in noise came when my friend Paul Parry who owns Bad Dog Designs in the UK sent me an email pointing me to a YouTube video of one of his creations he calls The Fool’s Lantern.

 fig-02.jpg

Paul specializes in creating unusual Nixie tube-based clocks. In this case, he’s also added a 16 x 16 array of WS2812 tricolored LEDs, which are commonly known as NeoPixels. While I was drooling over the flashing lights, my eye was drawn to an effect that starts around 1:00 into the video. I’ve seen this effect, which is similar to the way in which blobs of liquid wax undulate and migrate in a lava lamp, on lighting displays before, but I’ve never known how to implement it.

When I emailed Paul to inquire further, he replied that he was using a modified version of an example program called “Noise” that he’d found included with the FastLED Library. I did a bit of rooting around and found a related example program called “NoisePlusPalette” that also comes with this library. I then “tweaked” this program and applied it to my 12 x 12 ping pong ball array, where each ball is equipped with its own NeoPixel (see also Ping Pong Ball Array Shines and Easily Add Motion and Orientation Sensing to Improve Your Projects).

fig-03.jpg

Further investigation revealed that the FastLED noise functions are based on something called Simplex noise that was created by Ken Perlin in 2001. Simplex noise provides a method for constructing n-dimensional noise. Based on Perlin noise, which was invented by Ken in 1983, Simplex noise was originally intended to create synthetic textures in computer-generated imagery (CGI), but it can be used for all sorts of weird and wonderful things, like implementing the lava lamp effect on my 12 x 12 ping pong ball array, for example.

You can see this effect in action on my array in this YouTube video. I think you’ll agree that this looks rather spiffy. Now I’m thinking of ways in which I can enhance this effect, such as making it react to sounds. One approach might be to change the colors based on the predominant frequencies; another might be to modify the speed of the effect based on the amplitude of the sound.

So many fun things to do... so little time to do them all in. How about you? Do you have any thoughts you’d care to share on anything you’ve seen here.

About the Author(s)

Clive 'Max' Maxfield

Clive "Max" Maxfield is a freelance technical consultant and writer. Max received his BSc in Control Engineering in 1980 from Sheffield Hallam University, England and began his career as a designer of central processing units (CPUs) for mainframe computers. Over the years, Max has designed everything from silicon chips to circuit boards and from brainwave amplifiers to Steampunk Prognostication Engines (don't ask). He has also been at the forefront of Electronic Design Automation (EDA) for more than 35 years.

Well-known throughout the embedded, electronics, semiconductor, and EDA industries, Max has presented papers at numerous technical conferences around the world, including North and South America, Europe, India, China, Korea, and Taiwan. He has given keynote presentations at the PCB West conference in the USA and the FPGA Forum in Norway. He's also been invited to give guest lectures at several universities in the US and at Oslo University in Norway. In 2001, Max "shared the stage" at a conference in Hawaii with former Speaker of the House, "Newt" Gingrich.

Max is the author and/or co-author of a number of books, including Designus Maximus Unleashed (banned in Alabama), Bebop to the Boolean Boogie (An Unconventional Guide to Electronics), EDA: Where Electronics Begins, FPGAs: Instant Access, and How Computers Do Math.

Sign up for the Design News Daily newsletter.

You May Also Like