From 0b43bd6fe007d726fd6ff9c2c9b4998768fa5696 Mon Sep 17 00:00:00 2001 From: Mikey Sklar Date: Sat, 18 Nov 2017 18:00:21 -0700 Subject: [PATCH] Ported to CircuitPython, Tested on Gemma M0 and Trinket M0 --- .../.Larson_Scanner_Shades.ino.swp | Bin 0 -> 12288 bytes .../Larson_Scanner_Shades.ino | 41 ++++++++++++++++++ .../Larson_Scanner_Shades.py | 37 ++++++++++++++++ Larson_Scanner_Shades/README.md | 4 ++ 4 files changed, 82 insertions(+) create mode 100644 Larson_Scanner_Shades/.Larson_Scanner_Shades.ino.swp create mode 100644 Larson_Scanner_Shades/Larson_Scanner_Shades.ino create mode 100644 Larson_Scanner_Shades/Larson_Scanner_Shades.py create mode 100644 Larson_Scanner_Shades/README.md 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 0000000000000000000000000000000000000000..fc5b15b22ab4582b4ee711f52649bc1fc08118f9 GIT binary patch literal 12288 zcmeI2&u<$=6vwAM0;L76Jv`DwZTYuT)K-Zr(WXsP(hxPGNa0|OcgOMA>zQR|wvJVm z_MhPhHzXvAIB@5}KLBTXU~L_F#Dj?fV;d>2mXu zKszVIm!F^AeZKpPc=o9fZj#7s8Wv7&&Kf&(I@8U>Mlv~e^Jfc(tu^H)-lnaAj3#;7 zn(8RC4&6k}`)Ov!D)O!srE@>BrjgnVqxWMu%yRAfn@VOzo4x+d+<7(auje{euC*yM zMA6@gq%kV%?~LTJvrTR6u_5vT6L>WVNfC(@GCcp%kz>x%edP+RT%IR{oTK1=2=*uB@On?b60Vco%m;e)C0!)AjFaajO z1em~okbsPZc>bCY-@cCE@&Et9@Bg3A3h@*41N0R72AV))=o9D;bQ@ZS-h$3Sr=j29 z6yi7ND`*N`hWNfC(^x{|$jhf+&b6)*1Dvfo`Q3r`BQYe5TW;$*0?TUnQwZfoN@4k^8Af6Q8Theq2Kr9^;9(%LEV#n6f8&5&_Ll!Vsb{w$-J-)&cf6kyp;2aD0RQ-SMcf6E2IZ7g2;_ z7#4&NDkIP?0M==yD7NOJNA6S{ay*kh8ikSxY4c?w*Fv7(J8%~jSHyN}2o=*rHvX1} zD$O(sBuaFOOwU8QwDB}v5f7}6DX})i>+w*CFdHhlN9}s~T6Kz)ZCj_kwx*cHC+c_% z6}_b9YDtLj8ZPobP4V$5sEJT<7h*NkC~<5;(upn|&MeHS+r=hrq9l(Mt-f?hb97Do2@>+M AB>(^b literal 0 HcmV?d00001 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