Pixel Chaser
Part of the Displays and Sensors section of Coddy's Arduino journey. Lesson 15 of 24.
A light that runs round a ring is one pixel lit at a time, moving to the next one on each step. A for loop gives the pixel number:
for (int i = 0; i < 16; i++) {
ring.clear(); // the old pixel goes off
ring.setPixelColor(i, orange); // the new one lights
ring.show();
delay(100);
}clear() comes first, so the last pixel goes dark in the same show() that lights the next. Without it, every pixel stays lit and the ring fills up.
The loop stops after pixel 15, loop() runs again, and i starts at 0: the light goes round and round.
Challenge
EasyMake an orange light run round the ring:
- light one pixel at a time, from 0 up to 15
- 100 ms on each pixel
- after 15, start again at 0
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);
uint32_t orange = ring.Color(255, 40, 0);
void setup() {
ring.begin();
}
void loop() {
// light one pixel at a time, 0 to 15, 100 ms each
}
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 RollerPractice on your own: Arduino playground