Ported to CircuitPython, Tested on Gemma M0 and Trinket M0
This commit is contained in:
parent
797c51f8b2
commit
0b43bd6fe0
4 changed files with 82 additions and 0 deletions
BIN
Larson_Scanner_Shades/.Larson_Scanner_Shades.ino.swp
Normal file
BIN
Larson_Scanner_Shades/.Larson_Scanner_Shades.ino.swp
Normal file
Binary file not shown.
41
Larson_Scanner_Shades/Larson_Scanner_Shades.ino
Normal file
41
Larson_Scanner_Shades/Larson_Scanner_Shades.ino
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
||||
37
Larson_Scanner_Shades/Larson_Scanner_Shades.py
Normal file
37
Larson_Scanner_Shades/Larson_Scanner_Shades.py
Normal file
|
|
@ -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
|
||||
4
Larson_Scanner_Shades/README.md
Normal file
4
Larson_Scanner_Shades/README.md
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# Larson_Scanner_Shades
|
||||
|
||||
Code to accompany this tutorial:
|
||||
https://learn.adafruit.com/larson-scanner-shades
|
||||
Loading…
Reference in a new issue