# RGB & HSV NeoPixel Dialer

## Introduction

![](https://cdn-learn.adafruit.com/assets/assets/000/051/326/medium800/led_pixels_P1060454.jpg?1519824638)

Have you ever wanted a certain color for a NeoPixel project and had trouble figuring out which RGB or HSV values to enter? You can use web colors to try and get specific colors but you never know how it will look in real life until you load up your code and see it in action. This project allows you to use potentiometers to adjust the red, green and blue values individually in real time to fine tune NeoPixel colors and to see exactly how RGB and HSV values from the code work in practice.

https://www.youtube.com/watch?v=h12extrrFZs

# Materials
### Part: Feather M0 Express
quantity: 1
Microcontroller to run CircuitPython
[Feather M0 Express](https://www.adafruit.com/product/3403)

### Part: Standard LCD 16x2 + extras - white on blue
quantity: 1
LCD screen to display data
[Standard LCD 16x2 + extras - white on blue](https://www.adafruit.com/product/181)

### Part: NeoPixel Stick - 8 x 5050 RGB LED with Integrated Drivers
quantity: 1
NeoPixels
[NeoPixel Stick - 8 x 5050 RGB LED with Integrated Drivers](https://www.adafruit.com/product/1426)

### Part: Panel Mount 10K Log Potentiometer
quantity: 4
Potentiometers - 3 for RGB and 1 for the LCD brightness
[Panel Mount 10K Log Potentiometer](https://www.adafruit.com/product/3391)

### Part: Super Bright Red 5mm LED
quantity: 1
5mm Red LED for pot
[Super Bright Red 5mm LED](https://www.adafruit.com/product/297)

### Part: Super Bright Blue 5mm LED
quantity: 1
5mm Blue LED for pot
[Super Bright Blue 5mm LED](https://www.adafruit.com/product/301)

### Part: Super Bright Green 5mm LED
quantity: 1
5mm Green LED for pot
[Super Bright Green 5mm LED](https://www.adafruit.com/product/300)

### Part: 5mm Plastic Flat LED Holder - Pack of 5
quantity: 1
LED holders to mount individual 5mm LEDs
[5mm Plastic Flat LED Holder - Pack of 5](https://www.adafruit.com/product/2175)

### Part: Potentiometer Knob - Soft Touch T18 - White
quantity: 2
White Pot knob - 1 will be painted green
[Potentiometer Knob - Soft Touch T18 - White](https://www.adafruit.com/product/2047)

### Part: Potentiometer Knob - Soft Touch T18 - Red
quantity: 1
Red pot knob
[Potentiometer Knob - Soft Touch T18 - Red](https://www.adafruit.com/product/2046)

### Part: Potentiometer Knob - Soft Touch T18 - Blue
quantity: 1
Blue pot knob
[Potentiometer Knob - Soft Touch T18 - Blue](https://www.adafruit.com/product/2048)

### Part: Adafruit Perma-Proto Half-sized Breadboard PCB - Single
quantity: 1
Board for soldering the circuit
[Adafruit Perma-Proto Half-sized Breadboard PCB - Single](https://www.adafruit.com/product/1609)

### Part: Hook-up Wire Spool Set - 22AWG Solid Core
quantity: 1
Wire for the circuit
[Hook-up Wire Spool Set - 22AWG Solid Core](https://www.adafruit.com/product/1311)

### Part: M2.5 Screws
quantity: 1
Screws for mounting the Feather and Perma Proto in the bottom of the case
[M2.5 Screws](https://www.adafruit.com/product/3299)

### Part: PLA Filament for 3D Printers - 1.75mm Diameter - 1KG - Silver
quantity: 1
Silver filament for the case
[PLA Filament for 3D Printers - 1.75mm Diameter - 1KG - Silver](https://www.adafruit.com/product/2063)

### Part: PLA Filament for 3D Printers - 1.75mm Diameter - White - 1KG
quantity: 1
White filament for the 5mm LED diffusers
[PLA Filament for 3D Printers - 1.75mm Diameter - White - 1KG](https://www.adafruit.com/product/2067)

# RGB & HSV NeoPixel Dialer

## Circuit

The Feather M0 Express board acts as the brains of the operation, since it has the perfect amount of pins to control the LCD, analog potentiometers and NeoPixels. The three potentiometers that are controlling the RGB values are connected to analog pins 0, 1 and 2. The NeoPixels' data pin is pin 13 and then LCD uses six of the digital pins (pins 5, 6, 9, 10, 11 and 12).

![](https://cdn-learn.adafruit.com/assets/assets/000/051/330/medium800/led_pixels_neopixelDialer_bb.jpg?1519826452)

[For a more detailed walkthrough on how to hook-up a Character LCD screen, checkout this Learn guide](https://learn.adafruit.com/character-lcds)
The main portion of the circuit is soldered to a perma proto board. This makes laying out the components very simple and allows for Ground and 5V to be easily accessible using the rails. The LCD screen is not soldered directly to the board. Instead a row of female headers are soldered in so that the LCD can be removed easily if needed and to lift it to the proper height for the top of the enclosure. The LCD needs an potentiometer to control the screen brightness, which is located to its left.

The individual 5mm LEDs are only receiving power and ground from the Feather M0 Express, so that they turn on whenever the board receives power. They're being used as labels to help identify which value the potentiometers are controlling.

# RGB & HSV NeoPixel Dialer

## RGB CircuitPython Code Using the NeoPixel Library

Info: 

[For a more complete walkthrough on how to use CircuitPython please reference this Learn guide.](../../../../welcome-to-circuitpython)

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/NeoPixel_Dialer/RGB_NeoPixel_Dialer/code.py

The goal of the code is to have the three potentiometers each control the red, green and blue values of the NeoPixels. The NeoPixels should update in real time according to the values read from the potentiometers and then those same values should appear on the LCD's screen.

The analog values produced by the potentiometers are converted to digital values by dividing the analog value by 257, giving a minimum value of 0 and a maximum value of 255. This value exists as a `float`. For the values to be able to be used as a value for the NeoPixels they need to be converted to integers with `int`.

For these same values to be used with the LCD screen, they need to be converted to strings, which is done with `str`. The only issue that remains is that the values will appear with their decimal points, making them incredibly long and unable to fit on the screen. The decimal is removed by using the truncate function (`math.trunc`) from the Python math library. Finally, `lcd_clear()` has to be called at the end of the loop so that the LCD refreshes to reflect the changing values from the potentiometers.

# RGB & HSV NeoPixel Dialer

## HSV CircuitPython Code Using the FancyLED Library

Info: 

[Learn Guide for the CircuitPython FancyLED Library ](https://learn.adafruit.com/fancyled-library-for-circuitpython/overview)
You don't have to remain confined to RGB values though. The FancyLED library in CircuitPython allows you to use HSV, or hue, saturation and value, to affect the NeoPixel strip's color.

The code is very similar to the NeoPixel library RGB code that we just looked at. The goals are still the same: have the pots control the three values that affect the NeoPixel strip's color (in this case HSV) and have these values display on the LCD in real time.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/NeoPixel_Dialer/HSV_FancyLED_NeoPixel_Dailer/code.py

The first change is the division of the analog voltage value by itself (`pin.value / 65535`) so that the minimum value read is 0 and the maximum is 1, since that is the range of HSV values.

Next, are the functions `round_pot_h`, `round_pot_s` and `round_pot_v`. These functions return a rounded number for the HSV values. Since HSV uses a decimal range between 0 and 1, the numbers can be very long in length, which won't fit on the LCD screen. Here, the numbers are being rounded to 2 decimal places so that all three HSV values can fit comfortably on the screen. However, you can easily change the number of decimal places to suit your needs.

In the loop, the HSV values are assigned to `color`, which is then converted from float HSV values to integer RGB values using `pack()` from the FancyLED library. These integer values are then written to the NeoPixel strip using `strip.fill(packed)` from the NeoPixel library.

For the LCD portion, the only big change from the NeoPixel RGB value code is that functions are being used and called to round the HSV values. This was done to avoid memory allocation issues.

Also, you'll notice that the values are not being converted to integers for the LCD. This is because although we need integers to write the colors to the NeoPixel strip, we want to see the float HSV values on the screen. Just like the RGB value code, the rounded HSV values are sent to the LCD as strings with `str`.

Some examples of HSV values being dialed in.

![led_pixels_P1060498.jpg](https://cdn-learn.adafruit.com/assets/assets/000/051/381/medium640/led_pixels_P1060498.jpg?1519912431)

![led_pixels_P1060499.jpg](https://cdn-learn.adafruit.com/assets/assets/000/051/382/medium640/led_pixels_P1060499.jpg?1519912449)

![led_pixels_P1060510.jpg](https://cdn-learn.adafruit.com/assets/assets/000/051/383/medium640/led_pixels_P1060510.jpg?1519912468)

![led_pixels_P1060512.jpg](https://cdn-learn.adafruit.com/assets/assets/000/051/384/medium640/led_pixels_P1060512.jpg?1519912499)

# RGB & HSV NeoPixel Dialer

## 3D Printing

# Case Design
The case was designed in Fusion360 to have all of the components available on the top of the box with a hole in the back that allows the Feather M0 Express's USB port to be accessible. The bottom of the case has standoffs designed to screw the Feather and perma proto board in place with M2.5 screws. The case is also a snap fit case, making opening and closing it very simple.

Planning the case's layout and measurements

![led_pixels_IMG_4890.jpg](https://cdn-learn.adafruit.com/assets/assets/000/051/332/medium640/led_pixels_IMG_4890.jpg?1519828053)

![led_pixels_IMG_4891.jpg](https://cdn-learn.adafruit.com/assets/assets/000/051/333/medium640/led_pixels_IMG_4891.jpg?1519828065)

[When designing a snap fit case in Fusion360, try following this great video tutorial from the Ruiz brothers:]()
https://www.youtube.com/watch?v=VVmOtM60VWw

# Printing
The case was printed with 20% infill and .2mm layer height. No supports are needed. Silver PLA filament was used to act as a neutral, yet still bright, color with the lights.

![](https://cdn-learn.adafruit.com/assets/assets/000/051/343/medium800/led_pixels_P1060462.jpg?1519829208)

[Download the .STL files from Thingiverse](https://www.thingiverse.com/thing:2809671)
[Download the Fusion360 File](http://a360.co/2oRKcSh)
## LED Diffusers
The single 5mm LEDs used are very bright and need to be diffused so that you can still look comfortably at the NeoPixel strip. There is a great diffuser model on Thingiverse designed by 3dprintsolutions that fits perfectly over a 5mm LED. But since the LEDs are in LED holders, they aren't fully exposed and as a result the provided model is too long. You can shorten the model though in your slicer by performing a cut. A cut at Z height 6.7 provided the best fit, sitting flush with the case. You may find that you need to print this a bit smaller, between 93%-95% since the lip found on the bottom of LEDs is not being used to catch onto the diffuser's housing.

[Download the 5mm LED Diffuser Model by 3dprintsolutions on Thingiverse](https://www.thingiverse.com/thing:1639312)
![](https://cdn-learn.adafruit.com/assets/assets/000/051/342/medium800/led_pixels_cut_5mm_led_diffuser.jpg?1519828705)

This cut model was then printed with 20% infill and .2mm layer height with white PLA. Supports were used as suggested by 3dprintsolution, the designer.

Info: 

# RGB & HSV NeoPixel Dialer

## Assembly

Now it's time to solder everything together and fit everything snugly into the housing. Begin by placing all of the components onto the perma proto board and then running wires to the Feather M0 Express and other components. As mentioned in the Circuit portion of the guide, female headers were used for the LCD to plug into so that it can be removed easily and to lift it up high enough for the top of the case.

Circuit layout. Poster tack can be helpful when placing through-hole parts since it keeps everything in place and is easily removed after soldering.

![led_pixels_IMG_4907.jpg](https://cdn-learn.adafruit.com/assets/assets/000/051/344/medium640/led_pixels_IMG_4907.jpg?1519829584)

![led_pixels_IMG_4908.jpg](https://cdn-learn.adafruit.com/assets/assets/000/051/345/medium640/led_pixels_IMG_4908.jpg?1519829599)

![led_pixels_IMG_4909.jpg](https://cdn-learn.adafruit.com/assets/assets/000/051/346/medium640/led_pixels_IMG_4909.jpg?1519829648)

For the individual LEDs be sure to use heat shrink to avoid any shorts. You can use color coded heat shrink to help keep the clear LEDs straight.

![](https://cdn-learn.adafruit.com/assets/assets/000/051/356/medium800/led_pixels_IMG_4910.jpg?1519829906)

Info: 

After you've finished soldering and have tested everything, it's time to put everything into the housing. First, use M2.5 screws to secure the Feather M0 Express board and perma proto board to the bottom of the case. Also slot the 5mm LED holders into the top of the case. Next, feed the potentiometers and individual LEDs into their holes. Secure the potentiometers with their included washer. Then, press the NeoPixel strip into its slot. Depending on your printer's tolerances you may need to use a small piece of electrical tape to help keep it in place; otherwise the housing should hold the pixels securely. After that, you're ready to close up the case, which should snap shut. With the headers the LCD's screen should be flush with the top of the case and fit properly in its cutout without much adjustment.

Laying out parts after soldering

![led_pixels_IMG_4964.jpg](https://cdn-learn.adafruit.com/assets/assets/000/051/357/medium640/led_pixels_IMG_4964.jpg?1519830054)

![led_pixels_IMG_4976.jpg](https://cdn-learn.adafruit.com/assets/assets/000/051/358/medium640/led_pixels_IMG_4976.jpg?1519830068)

# Finishing Touches
The knobs for the potentiometers help in labeling which color is being controlled. However, you may have noticed that there are no knobs with green markings. We can fix this with a simple Sharpie Paint marker. First, tape off the knob so that only the white strip is seen and then go to town with your Sharpie. You can use paint with a brush if you prefer, but the Sharpie is quick drying and less messy.

Taping and painting process for the green knob.

![led_pixels_IMG_5010.jpg](https://cdn-learn.adafruit.com/assets/assets/000/051/360/medium640/led_pixels_IMG_5010.jpg?1519830397)

![led_pixels_IMG_5011.jpg](https://cdn-learn.adafruit.com/assets/assets/000/051/361/medium640/led_pixels_IMG_5011.jpg?1519830411)

![led_pixels_IMG_5012.jpg](https://cdn-learn.adafruit.com/assets/assets/000/051/362/medium640/led_pixels_IMG_5012.jpg?1519830460)

Once everything is inside the case you're ready to dial in all of the colors of the rainbow!

![](https://cdn-learn.adafruit.com/assets/assets/000/051/359/medium800/led_pixels_P1060457.jpg?1519830135)


## Featured Products

### Adafruit Feather M0 Express

[Adafruit Feather M0 Express](https://www.adafruit.com/product/3403)
At the Feather M0's heart is an ATSAMD21G18 ARM Cortex M0+ processor, clocked at 48 MHz and at 3.3V logic, the same one used in the new&nbsp;[Arduino Zero](https://www.adafruit.com/products/2843). This chip has a whopping 256K of FLASH (8x more than the Atmega328 or 32u4) and...

Out of Stock
[Buy Now](https://www.adafruit.com/product/3403)
[Related Guides to the Product](https://learn.adafruit.com/products/3403/guides)
### Standard LCD 16x2 + extras

[Standard LCD 16x2 + extras](https://www.adafruit.com/product/181)
Standard HD44780 LCDs are useful for creating standalone projects.

- 16 characters wide, 2 rows
- White text on blue background
- Connection port is 0.1" pitch, single row for easy breadboarding and wiring
- Pins are documented on the back of the LCD to assist...

In Stock
[Buy Now](https://www.adafruit.com/product/181)
[Related Guides to the Product](https://learn.adafruit.com/products/181/guides)
### NeoPixel Stick - 8 x 5050 RGB LED with Integrated Drivers

[NeoPixel Stick - 8 x 5050 RGB LED with Integrated Drivers](https://www.adafruit.com/product/1426)
Make your own little LED strip arrangement with this stick of NeoPixel LEDs. We crammed 8 of the tiny 5050 (5mm x 5mm) smart RGB LEDs onto a PCB with mounting holes and a chainable design. Use only one microcontroller pin to control as many as you can chain together! Each LED is addressable as...

In Stock
[Buy Now](https://www.adafruit.com/product/1426)
[Related Guides to the Product](https://learn.adafruit.com/products/1426/guides)
### Panel Mount 10K Log Potentiometer (Breadboard Friendly)

[Panel Mount 10K Log Potentiometer (Breadboard Friendly)](https://www.adafruit.com/product/3391)
This potentiometer is a two-in-one, good in a breadboard or with a panel. It's a **log taper** 10K ohm potentiometer, with a grippy shaft. It's smooth and easy to turn, but not so loose that it will shift on its own. We like this one because the legs are 0.2" apart...

In Stock
[Buy Now](https://www.adafruit.com/product/3391)
[Related Guides to the Product](https://learn.adafruit.com/products/3391/guides)
### Super Bright Red 5mm LED (25 pack)

[Super Bright Red 5mm LED (25 pack)](https://www.adafruit.com/product/297)
Need some really bright LEDs? We are big fans of these clear red LEDs, in fact we use them exclusively in our kits. They are very bright and have about 20degree LED beam. They go easily into a breadboard and will add that extra zing to your project.

- Pack of 25 clear red...

In Stock
[Buy Now](https://www.adafruit.com/product/297)
[Related Guides to the Product](https://learn.adafruit.com/products/297/guides)
### Super Bright Blue 5mm LED (25 pack)

[Super Bright Blue 5mm LED (25 pack)](https://www.adafruit.com/product/301)
Need some really bright LEDs? We are big fans of these clear blue LEDs, in fact we use them exclusively in our kits. They are very bright and have about 20degree LED beam. They go easily into a breadboard and will add that extra zing to your project.

- Pack of 25 clear blue...

In Stock
[Buy Now](https://www.adafruit.com/product/301)
[Related Guides to the Product](https://learn.adafruit.com/products/301/guides)
### Super Bright Green 5mm LED (25 pack)

[Super Bright Green 5mm LED (25 pack)](https://www.adafruit.com/product/300)
Need some really bright LEDs? We are big fans of these clear green LEDs, in fact we use them exclusively in our kits. They are very bright and have about 20degree LED beam. They go easily into a breadboard and will add that extra zing to your project.

- Pack of 25 clear green...

In Stock
[Buy Now](https://www.adafruit.com/product/300)
[Related Guides to the Product](https://learn.adafruit.com/products/300/guides)
### 5mm Plastic Flat LED Holder - Pack of 5

[5mm Plastic Flat LED Holder - Pack of 5](https://www.adafruit.com/product/2175)
Keep your **5mm** LEDs in place with these little plastic LED holders. These are handy for projects using individual LEDs as&nbsp;they look sleek, and your LED won't budge. Slot the LED through the opening and you'll get a nice...

In Stock
[Buy Now](https://www.adafruit.com/product/2175)
[Related Guides to the Product](https://learn.adafruit.com/products/2175/guides)

## Related Guides

- [Adafruit Feather M0 Express](https://learn.adafruit.com/adafruit-feather-m0-express-designed-for-circuit-python-circuitpython.md)
- [Air Quality Monitor and Case](https://learn.adafruit.com/aqi-case.md)
- [PyPortal Case](https://learn.adafruit.com/pyportal-case.md)
- [CircuitPython Hardware: PCA9685 PWM & Servo Driver](https://learn.adafruit.com/micropython-hardware-pca9685-pwm-and-servo-driver.md)
- [No-Code Indoor Air Quality Monitor with Separate Display](https://learn.adafruit.com/no-code-indoor-air-quality-monitor-with-separate-display.md)
- [BLE Light Switch with Feather nRF52840 and Crickit](https://learn.adafruit.com/bluetooth-light-switch-with-crickit-and-nrf52840.md)
- [Dotstar Featherwing in CircuitPython](https://learn.adafruit.com/dotstar-featherwing-in-circuitpython.md)
- [Solderless Robot Toy Xylophone](https://learn.adafruit.com/solderless-robot-toy-xylophone.md)
- [USB Host to BLE Keyboard Adapter](https://learn.adafruit.com/esp32-s3-usb-to-ble-keyboard-adapter.md)
- [3D Scans for Low Poly Statues](https://learn.adafruit.com/low-poly-3d-scans-for-3d-printing.md)
- [NFC Raspberry Pi Media Player](https://learn.adafruit.com/nfc-raspberry-pi-media-player.md)
- [Ninja Timer: Giant 7-Segment Display](https://learn.adafruit.com/ninja-timer-giant-7-segment-display.md)
- [Making Adabot: Part 2](https://learn.adafruit.com/making-adabot-part-2.md)
- [Welcome to CircuitPython!](https://learn.adafruit.com/welcome-to-circuitpython.md)
- [Creating and sharing a CircuitPython library](https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library.md)
- [Compost Friend!](https://learn.adafruit.com/compost-optimization-machine.md)
