Colours on a Pixel Ring
Part of the Displays and Sensors section of Coddy's Arduino journey. Lesson 13 of 24.
This ring holds 16 NeoPixels on one data wire. The first pixel passes the rest of the data on to the next, so one show() sets them all. They are numbered 0 to 15.
ring.Color(red, green, blue) packs a colour into one number, so you can keep it in a variable and use it again. Its type is uint32_t: a whole number of 32 bits that is never negative, big enough for all three parts.
uint32_t purple = ring.Color(150, 0, 255);
ring.setPixelColor(3, purple);
ring.setPixelColor(7, purple);
ring.show();A pixel you never give a colour stays off. 255 for all three parts is white.
Challenge
EasyThe ring is on pin 6. Light four pixels, a quarter of the ring apart:
- pixel 0 red, pixel 4 green, pixel 8 blue, pixel 12 white
- make each colour with
ring.Color(), every part 0 or 255 - leave the other pixels off
Press Run, then Check.
Try it yourself
#include <Adafruit_NeoPixel.h>
// 16 pixels, data on pin 6
Adafruit_NeoPixel ring(16, 6, NEO_GRB + NEO_KHZ800);
void setup() {
ring.begin();
// pixel 0 red, 4 green, 8 blue, 12 white
ring.show();
}
void loop() {
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Displays and Sensors
1Seven-Segment Displays
Seven-Segment DisplayDigit Patterns in BytesCount on the DisplayCountdown to ZeroDice Roller3NeoPixels
Your First NeoPixelColours on a Pixel RingFill and Clear the RingPixel ChaserNeoPixel BrightnessRainbow RingPractice on your own: Arduino playground