/ Larson_Scanner_Shades / Larson_Scanner_Shades.ino
Larson_Scanner_Shades.ino
 1  // SPDX-FileCopyrightText: 2017 Mikey Sklar for Adafruit Industries
 2  //
 3  // SPDX-License-Identifier: MIT
 4  
 5  #include <Adafruit_NeoPixel.h>
 6  
 7  #define N_LEDS 22
 8  #define PIN     4
 9  
10  Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800);
11  
12  void setup() {
13    strip.begin();
14  }
15  
16  int pos = 0, dir = 1; // Position, direction of "eye"
17  
18  void loop() {
19    int j;
20  
21    // Draw 5 pixels centered on pos.  setPixelColor() will clip any
22    // pixels off the ends of the strip, we don't need to watch for that.
23    strip.setPixelColor(pos - 2, 0x100000); // Dark red
24    strip.setPixelColor(pos - 1, 0x800000); // Medium red
25    strip.setPixelColor(pos    , 0xFF3000); // Center pixel is brightest
26    strip.setPixelColor(pos + 1, 0x800000); // Medium red
27    strip.setPixelColor(pos + 2, 0x100000); // Dark red
28  
29    strip.show();
30    delay(30);
31  
32    // Rather than being sneaky and erasing just the tail pixel,
33    // it's easier to erase it all and draw a new one next time.
34    for(j=-2; j<= 2; j++) strip.setPixelColor(pos+j, 0);
35  
36    // Bounce off ends of strip
37    pos += dir;
38    if(pos < 0) {
39      pos = 1;
40      dir = -dir;
41    } else if(pos >= strip.numPixels()) {
42      pos = strip.numPixels() - 2;
43      dir = -dir;
44    }
45  }