// Forum: https://forum.arduino.cc/t/can-you-use-the-strip-fill-command-to-fill-from-the-opposite-direction/1189165/
// This Wokwi project: https://wokwi.com/projects/381398312933908481
#include <Adafruit_NeoPixel.h>
#define LED_PIN 6
#define LED_PIN2 5
#define NUM_PIXELS 18
Adafruit_NeoPixel strip(NUM_PIXELS, LED_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip_b(NUM_PIXELS, LED_PIN2, NEO_GRB + NEO_KHZ800);
void setup() {
// These lines are specifically to support the Adafruit Trinket 5V 16 MHz.
// Any other board, you can remove this part (but no harm leaving it):
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
// END of Trinket-specific code.
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
strip_b.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip_b.show();
}
int pos = 0, dir = 1; // Position, direction of "eye"
// loop() function -- runs repeatedly as long as board is on ---------------
void loop() {
// Fill along the length of the strip in various colors...
uint32_t softred = strip.Color(255, 0, 55);
strip.show();
uint32_t softred_b = strip_b.Color(255, 0, 55);
strip_b.show();
//strip.fill(softred, 0, 18);
uint32_t softblue = strip.Color(55, 10, 255);
strip.show();
uint32_t darkred = strip.Color(18, 0, 0);
strip.show();
uint32_t mediumred = strip.Color(128, 0, 0);
strip.show();
uint32_t softblue_b = strip_b.Color(55, 10, 255);
strip_b.show();
int j;
// Draw 5 pixels centered on pos. setPixelColor() will clip any
// pixels off the ends of the strip, we don't need to watch for that.
//strip.setPixelColor(pos - 2, darkred); // Dark red
//strip.setPixelColor(pos - 1, mediumred); // Medium red
strip.setPixelColor(pos +2, softred);
strip.setPixelColor(pos +1, softred); // Center pixel is brightest
strip.setPixelColor(pos , softred);
strip.setPixelColor(pos -1, 0);
strip.setPixelColor(pos -2, 0);
strip.setPixelColor(pos -3, softred);
strip.setPixelColor(pos -4, softred); // Center pixel is brightest
strip.setPixelColor(pos -5, softred);
strip.setPixelColor(pos -6, 0);
strip.setPixelColor(pos -7, 0);
strip.setPixelColor(pos -8, softred);
strip.setPixelColor(pos -9, softred); // Center pixel is brightest
strip.setPixelColor(pos -10, softred);
strip.setPixelColor(pos -11, 0);
strip.setPixelColor(pos -12, 0);
strip.setPixelColor(pos -13, softred);
strip.setPixelColor(pos -14, softred); // Center pixel is brightest
strip.setPixelColor(pos -15, softred);
strip.setPixelColor(pos -16, 0);
strip.setPixelColor(pos -17, 0);
strip.setPixelColor(pos -18, softred);
strip.setPixelColor(pos -19, softred); // Center pixel is brightest
strip.setPixelColor(pos -20, softred);
strip.setPixelColor(pos -21, 0);
strip.setPixelColor(pos -22, 0);
strip.setPixelColor(pos -23, softred);
strip.setPixelColor(pos -24, softred); // Center pixel is brightest
strip.setPixelColor(pos -25, softred);
strip.setPixelColor(pos -26, 0);
strip.setPixelColor(pos -27, 0);
//strip.setPixelColor(pos + 1, mediumred); // Medium red
//strip.setPixelColor(pos + 2, darkred); // Dark red
strip.show();
delay(100);
// Rather than being sneaky and erasing just the tail pixel,
// it's easier to erase it all and draw a new one next time.
//strip.fill(softred, 0, 18);
for(j=-2; j<= 4; j++) strip.setPixelColor(pos+j, 0);{
// Bounce off ends of strip
pos += dir;
if(pos < 0) {
pos = 1;
//dir = -dir;
} else if(pos >= strip.numPixels()+26) {
pos = 1;
}
}
}
//for(int a=0; a<10; a++) {
//strip.setPixelColor(1, softred);
//strip.setPixelColor(8, softblue);
//strip_b.setPixelColor(12, softblue);
//delay(200);
//strip.clear();}
//strip.fill(softblue, 0, 18);
//colorWipe(strip.Color(255, 0, 55), 50); // Red
//colorWipe(strip.Color(55, 10, 255), 50); // Blue
// Some functions of our own for creating animated effects -----------------
// Fill strip pixels one after another with a color. Strip is NOT cleared
// first; anything there will be covered pixel by pixel. Pass in color
// (as a single 'packed' 32-bit value, which you can get by calling
// strip.Color(red, green, blue) as shown in the loop() function above),
// and a delay time (in milliseconds) between pixels.
void colorWipe(uint32_t color, int wait) {
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
strip.setPixelColor(i, color); // Set pixel's color (in RAM)
strip.show(); // Update strip to match
delay(wait); // Pause for a moment
}
}
void theaterChase(uint32_t color, int wait) {
for(int a=0; a<10; a++) { // Repeat 10 times...
for(int b=0; b<3; b++) { // 'b' counts from 0 to 2...
strip.clear(); // Set all pixels in RAM to 0 (off)
// 'c' counts up from 'b' to end of strip in steps of 3...
for(int c=b; c<strip.numPixels(); c += 3) {
strip.setPixelColor(c, color); // Set pixel 'c' to value 'color'
}
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}
}