My thermometer will have RGB leds beneath every nixie tube, to be able to light them up with different colors.
I decided to use pre-built modules, which include the RGB led and also all the required components (resistors…):
Within the led package, there’s a WS2812 (datasheet) control chip, which offers 16M of colors, 256 levels of brightness and a minimum refresh rate of 400Hz.
You can control those WS2812 drivers using a simple serial protocol: the different leds are chained (DOUT -> DIN) and the first one is connected to a digital PIN of your Arduino, the different commands are sent through.
Adafruit developed an handy library (NeoPixel) which you can install directly via Library Manager:
Let’s see how to use it.
First, you need to define a new Adafruit_NeoPixel object with some parameters:
#define PIXEL_PIN 3 #define PIXEL_COUNT 10 Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800); |
The first parameter identifies the PIN of your Arduino the leds are connected to and the second one the number of leds.
The third parmeter configures some aspects of the library and depends on the specific driver you’re using. Two different behaviors are defined:
[checklist]
- the sequence of the three primary colors (NEO_GRB o NEO_RGB o NEO_RGBW)
- the speed (frequency) the data is sent (NEO_KHZ400 o NEO_KHZ800)
[checklist]
In the setup() it’s mandatory to initialize the library:
strip.begin(); |
You can then change the color of each led with the following command:
strip.setPixelColor(#led, red, green, blue); |
the first parameter identifies the led your sending the command to (0 is the nearest to Arduino) and the next three ones are the values for each primary color.
To send the new colors to the leds, remember to use the command:
strip.show(); |
I wrote a sketch (Github) that changes the color of the leds using the sequence defined in a matrix:
uint8_t colors[8][3] = { {0,0,0}, {255,0,0}, {0,255,0}, {0,0,255}, {255,255,0}, {255,0,255}, {0,255,255}, {255,255,255}, }; |
Each time you press the button, the next color is used:
While I was testing the sketch, I noticed that the 5V output of my nixie power supplier wasn’t enough to power also the leds. Because of this, I added to my prototype an external linear regulator (7805) that powers both my Arduino and the leds: