diff --git a/Larson_Scanner_Shades/.Larson_Scanner_Shades.ino.swp b/Larson_Scanner_Shades/.Larson_Scanner_Shades.ino.swp new file mode 100644 index 000000000..fc5b15b22 Binary files /dev/null and b/Larson_Scanner_Shades/.Larson_Scanner_Shades.ino.swp differ diff --git a/Larson_Scanner_Shades/Larson_Scanner_Shades.ino b/Larson_Scanner_Shades/Larson_Scanner_Shades.ino new file mode 100644 index 000000000..03120e08b --- /dev/null +++ b/Larson_Scanner_Shades/Larson_Scanner_Shades.ino @@ -0,0 +1,41 @@ +#include + +#define N_LEDS 22 +#define PIN 4 + +Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN, NEO_GRB + NEO_KHZ800); + +void setup() { + strip.begin(); +} + +int pos = 0, dir = 1; // Position, direction of "eye" + +void loop() { + 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, 0x100000); // Dark red + strip.setPixelColor(pos - 1, 0x800000); // Medium red + strip.setPixelColor(pos , 0xFF3000); // Center pixel is brightest + strip.setPixelColor(pos + 1, 0x800000); // Medium red + strip.setPixelColor(pos + 2, 0x100000); // Dark red + + strip.show(); + delay(30); + + // Rather than being sneaky and erasing just the tail pixel, + // it's easier to erase it all and draw a new one next time. + for(j=-2; j<= 2; 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()) { + pos = strip.numPixels() - 2; + dir = -dir; + } +} diff --git a/Larson_Scanner_Shades/Larson_Scanner_Shades.py b/Larson_Scanner_Shades/Larson_Scanner_Shades.py new file mode 100644 index 000000000..d04ec761c --- /dev/null +++ b/Larson_Scanner_Shades/Larson_Scanner_Shades.py @@ -0,0 +1,37 @@ +import board +import neopixel +import time + +numpix = 22 # Number of NeoPixels +pixpin = board.D1 # Pin where NeoPixels are connected Gemma M0 = D1 | Trinket M0 = D4 +strip = neopixel.NeoPixel(pixpin, numpix, brightness=1, auto_write=False) +pos = 0 # position +direction = 1 # direction of "eye" + +while True: + strip[pos-2] = ([16,0,0]) # Dark red + strip[pos-1] = ([128,0,0]) # Medium red + strip[pos] = ([255,48,0]) # brightest + strip[pos+1] = ([128,0,0]) # Medium red + + if ( (pos + 2) < numpix ): + strip[pos+2] = ([16,0,0]) # Dark red, do not exceed number of pixels + + strip.write() + time.sleep(0.03) + + # Rather than being sneaky and erasing just the tail pixel, + # it's easier to erase it all and draw a new one next time. + for j in range(-2, 2): + strip[pos+j] = (0,0,0) + if ( (pos + 2) < numpix ): + strip[pos+2] = (0,0,0) + + # Bounce off ends of strip + pos += direction + if ( pos < 0 ): + pos = 1 + direction = -direction + elif ( pos >= (numpix - 1) ): + pos = numpix - 2 + direction = -direction diff --git a/Larson_Scanner_Shades/README.md b/Larson_Scanner_Shades/README.md new file mode 100644 index 000000000..3508cc851 --- /dev/null +++ b/Larson_Scanner_Shades/README.md @@ -0,0 +1,4 @@ +# Larson_Scanner_Shades + +Code to accompany this tutorial: +https://learn.adafruit.com/larson-scanner-shades