Musings, deliberations, and end results.
Felix Jen – 29 October 2020 – 12 min read
You would not believe your eyes, if ten million fireflies, lit up the world as I fell asleep. I like to make myself believe, that Planet Earth turns slowly. It’s hard to say that I’d rather stay awake when I’m asleep.
Red, Green, and Blue, the building blocks of our colorful world don’t just belong on traffic lights, monitor screens, and color wheels. They have their place on mechanical keyboards too—though some vehement opponents would feverishly disagree. Reminiscent of the olden days of Razer, Corsair, and Logitech, per-key RGB LED’s seem to be a thing of novelty and highfalutin opulence, we’ll examine the inner workings of LED’s in the modern keyboard scene.
“I will love the light for it shows me the way, yet I will endure the darkness for it shows me the stars.” – Og Mandino
Before we look at how to implement LED’s, let’s take a brief primer into the inner workings of the human mind and how we perceive color. Humans1 can perceive a certain portion of the electromagnetic spectrum using our eyes—what we typically call “color vision.” Present in human eyes are certain “cone cells” (named for their conical shape as viewed under a microscope) which are sensitive to three spectra of light—red, green, and blue. The brain receives optical stimulus from the three different cone cells in varying intensities depending on the “color” being observed, and then amalgamates them into a perceived “color.”
Admittedly, this distillation represents a outdated view of how humans perceive color vision.2 Modern canon of human vision suggests that our cone cells not as one-dimensional as they are described here; we’ll stick with this basic definition for now though to avoid the intricacies of opponent theory at this time.
“Mathematics expresses values that reflect the cosmos” – Deepak Chopra
Now that we got the basics of human sight out of the way, color theory becomes our next topic. Distilling the variegated world into a single unified theory is fraught with impossibly so, instead, we’ll focus on one in particular—additive color theory. The additive color mode is the method of producing color by mixing light. This is the mode you will find on monitors, TV’s, and other digital color electronics. Also known as RGB mode, this color modes relies on three important characteristics of light:
The combination of two of the common three additive primary colors (Red, Green, and Blue) in equal proportions produces an additive secondary color—cyan, magenta or yellow.3
This fundamental characteristic gets expanded on through the modern Grassmann’s Laws:4
Taking a reductionism of these laws, the summer, spice, and everything nice of additive color is simple—you mix varying intensities (read as, brightness) of red, green, and blue light to create every other color that humans can see. You’ll notice that this parallels how our human eyes see color with the distinct red, green, and blue cone cells, mixed in intensities.
“When your eyes freeze behind the grey window and the ghost of loss gets in to you, may a flock of colours, indigo, red, green and azure blue come to awaken in you a meadow of delight.” – John O’Donohue
Armed with the basics of additive color vision, we can now understand the principles behind RGB LED’s. To produce the a rainbow of colors, RGB LED’s make sure of three individual light emitting diodes (LED’s), one in each of the primary additive colors. These three LED’s are placed in extremely close proximity to one another essentially acting as a single light source. This results in additive color missing, as described through the Grassmann Laws above. By varying the intensity of each of the three separate color “channels,” a single RGB LED is able to produce any color that can be created through this mixing process. For those that deal with any form of digital design, this concept should be second nature, as it is the same process used to define colors digitally using \(rgb(x,y,z)\) color codes.
Much like an \(rgb(x,y,z)\) color code can be used to define a color in digital space, the same code can be used to define color in physical realm through the mixing of independent red, green, and blue color channels. We can analyze the color definition using relativistic definitions at first. In other words, we define \(0\% \le x,y,z \le 100\%\), or in more preferred notation, \(0 \le x,y,z \le 1\). The total brightness \(B\) can be expressed as the sum of the individual luminosities,5 such that \(\beta = x+y+z\)—as required by the fourth Grassmann Law, also known as Abney’s Law. To put this less mathematically for the numerically disinclined, each color channel (red, green, and blue) can be anywhere from off to full brightness. The exact color and brightness of the combined light depends on the exact combination of these brightness values.
With this definition of the possible color spectra available, we can run through some cursory examples in additive color mixing. As per our initial discussion on the additive mode, we can mix equal amounts of Red and Green light to produce a cyan color. We’ll assume that we are making Red and Green both shine at half brightness and thus define the resultant as:
\[rgb(x,y,z) | x=0, y=0.5, z=0.5\] \[\beta = 0 + 0.5 + 0.5 = 1\]Before the graphic designers reading this proceed to burn me at the stake, I specified this was a abstraction of the RGB color code using a relativistic expressions of brightness—hence why I broke out \(x,y,z\) from the actual RGB definition. While such a relativistic definition is useful in the abstract, it is not representative of the real world’s digital color reproduction you may be aware of.
We now move from the relativistic definition into a true digital color representation in the RGB code. To do this, we’ll introduce a new notation: \(rgb(R,G,B)\) such that \(0 \le R,G,B \le 255\). Note that 255 is a significant value here. As computers operate in the binary system, they must transmit values in the form of bits. Conveniently, \(2^8 = 256\) and thus, we can represent a total of 256 possible luminosity values using 8 bits—a byte.6 We use 255 as our full brightness value since we must leave 1 value available for “completely off” also defined as 0. We will complete our definitions using the below additional definitions, tying in our previous values:
\[\begin{cases} R = x \times 255 \\ G = y \times 255 \\ B = z \times 255 \end{cases}\]With this new notation in hand, let’s redefine our cyan color into the following:7
\[\begin{cases} R = 0 \times 255 = 0 \\ G = 0.5 \times 255 = 128 \\ B = 0.5 \times 255 = 128 \end{cases}\]Our resulting RGB color code, useful in the digital world is \(rgb(0,128,128)\), a value which will appease everyone who works in digital design or print media.
“Darkness cannot drive out darkness: only light can do that.” – Dr. Martin Luther King Jr.
Before we go on, for completeness, let’s add a quick definition of “darkness” into the mix. In the bright and luminous world of additive color, we define darkness as the absence of light. On one hand, this is related to total luminosity as we defined it, \(B\), but is distinct in a few ways. First of all, darkness is not a properly of light emitters as we know them in LED’s; rather they represent a form of “lightness” only really found in displays. If you’ve survived to the age of comprehending this post, you are certainly subconsciously aware that you can not have a light that shines “dark gray.” Rather, the light merely shines at a lower intensity of “white.”
How do we get dark gray then, if no light source actually is capable of emitting “dark gray” as a color itself. The answer lies in the darkness—or more technically, “lightness” of a color. In a pitch black background, the presence of a small amount of white light will turn such area to be “dark gray,” adding “lightness” to the area. This puts us firmly within a color mode known as HSL (Hue, Saturation, Lightness), but we won’t stray too far into this.
Instead, we’ll define the “black content” of an RGB color code, which is an effective inverse of the lightness of a color. We start with a fundamental principle, a color is only as dark as the highest luminosity of its components. This should be fairly intuitive: if you have Red at full brightness, with Green and Blue both off, the color is still at full brightness. I’ll call this highest luminosity value \(\Lambda\), such that \(\Lambda = \max(x,y,z)\) using our relativistic definitions from earlier.8 We’ll then define the “black content” to be \(b\), such that \(b = 1 - \Lambda\).
Under this definition, we can see that \(b\) is the additive inverse of maximum luminosity \(\Lambda\), or how far the color is from being full brightness. Note that “black content” is distinct from “total luminosity/brightness” that we defined earlier as the sum of the individual \(x,y,z\) values. When dealing with RGB LED’s (not in a digital display context), it is “total luminosity” which carries the day, not “black content.”
For completeness, we can translate from RGB to HSL using the following equations though they serve no real practical purpose here.9 The mathematically disinclined should shield their eyes.
\[I = \frac{x+y+z}{3}\] \[S = 1 - \frac{3}{x+y+z}\min(x,y,z)\] \[H = \begin{cases} \arccos\left(\frac{ (x-y) + (x-z)}{ 2\sqrt{ (x-y)^2 + (x-z)(y-z) } } \right) \bigg|_{y \gt z} \\ 360 - \arccos\left(\frac{ (x-y) + (x-z)}{ 2\sqrt{ (x-y)^2 + (x-z)(y-z) } } \right) \bigg|_{y \lt z} \end{cases}\]“You can’t take the sky from me.” – Joss Whedon, Firefly
While Obi-Wan would have you believe that only the Sith deal in absolutes, the digital world we live in does too. A core tenet of digital electronics is the bivalence of states a component may take. At any time, a component may either be “on” or “off,” there is no in between. A component may not be 50% on at any singular point in time. This is why digital circuits are frequently considered to be “binary” with 1 representing an On state and 0 representing an Off state. Such bivalence was casually referenced in our above definition of RGB using the relativistic definitions, with the maximum On state taking the value of 1 and the Off state taking the value of 0.
The bivalence of digitality is in stark contrast to the multiple spectra of the analog world, which can exist in any arbitrary state between 1 and 0. Everyone likely has had experiencce with analog technology at some point—most notably in the volume control of speakers. Rather than being completely muted or at max volume, you have a volume slider that can take any arbitrary value in between. This is the core difference between an analog and a digital system and will be critical in the remainder of this discussion.
So far, we’ve talked about changing the brightness of LED’s as if they were traditional analog devices, taking any possible brightness between fully on at maximum brightness and off. This has been a small lie. Light emitting diodes are known as “constant-current devices.” In brief, constant current devices draw a constant current (doh…) during their operation while the voltage they take may vary within a range. Like most light sources, LED’s will vary in brightness depending on the amount of current passing through them.10 A lower current applied through an LED will reduce the brightness of the LED, up to a point where it no longer lights up at all.
Unfortunately, changing current on the fly is not a simple task. An LED is, at its core, a diode device (the D in LED) and therefore passing through all current with a slight voltage drop. In terms of current, an LED connected to a power source and ground will act as a dead short, allowing an extreme amount of current to flow—instantly killing the LED. To get around this problem, a resistor is added in series to the LED to limit total current flowing through the LED. A representative circuit for a single LED connected through a power source is thus shown below:
Ignoring the \(1000\Omega\) value of the resistor for now, we can briefly use Ohm’s Law to describe this circuit as this will come in handy later. The text of Ohm’s law states that the current through a conductor between two points is directly proportional to the voltage across the two points and is inversely proportional to the resistance between those two points. In an equation, this presents us with the common formula:
\[I = \frac{V}{R}\]Since we are focusing on the LED, we want to know the current flowing through the LED. Ohm’s law specifies that we must pick two points to measure current across. Conveniently, two points are pretty self-evident, the voltage source and ground—the voltage source is before the LED and ground is after the LED. The current will flow between these two points taking only one path, through the LED itself. Furthermore, Ohm’s law dictates we analyze the voltage across the two points—the differential of the voltage. A characteristic of diodes is their “voltage drop.” This voltage drop creates a voltage differential across the LED, often called the forward voltage, \(V_f\). Therefore, we
[This post is currently a work in progress.]
While most humans are indeed capable of perceiving color vision, there are subsets of individuals suffer from color vision deficiency (color blindness) in the forms of monochromacy, dichromacy, and anomalous trichromacy. While the forgoing does apply to these individuals, the intricacies of color vision deficiency are left out for brevity. [Back]
J. K. Bowmaker & H. J. Dartnall, Visual pigments of rods and cones in a human retina., 298 J. Physiol. 501, 505 (noting that cone cells are not only receptive in a single wavelength of light, but rather an overlapping spectra). See also, David Briggs, The Dimensions of Color, Trichromacy and Opponency for a more in-depth look on the modern approach to color vision. [Back]
See David Briggs, The Dimensions of Color, Additive Mixtures for a more detailed explanation of how these primary colors interact to create secondary color. [Back]
David H. Krantz, Color measurement and color theory: I. Representation theorem for Grassmann structures, 12 J. Mathematical Psych. 283, 284. Note that Grassmann’s Laws’ corollaries are omitted for brevity and lack of relevance. [Back]
Luminosity is the amount of light emitted by a source whereas brightness is the amount of light received by an observer. While these terms are technically distinct, in that luminosity is an absolute value independent of an observer, they are being used interchangeably here to match the definitions within the Grassmann Laws. [Back]
I will not be covering the basis of binary mathematics in this post and this discussion of numerical representation is merely just as survey of the subject. [Back]
Values for \(R,G,B\) are rounded down to their nearest whole number as electronics conventions typically dictate. While \(=\) is technically incorrect, it will be used as the \(\approx\) symbol requires additional effort to insert and is merely a superficial distinction. [Back]
It does not make sense to define “black content” in a byte form, as this is not a value that is digitally reproduced. Rather, it is an inherent properly of a given RGB color code itself. [Back]
Allan Hanbury & Jean Serra, A 3D-polar Coordinate Colour Representation Suitable for Image Analysis. Pattern Recognition and Image Processing Group Technical Report 77, Vienna Uni. of Tech. (2002). [Back]
The exact nature of electroluminescence and band gap emissivity are out of my scope of knowledge, though the principle has been applied since the late 1900’s to develop a variety of LED’s. [Back]