Skip to content

Instantly share code, notes, and snippets.

@Neradoc
Last active September 18, 2016 13:54
Show Gist options
  • Save Neradoc/b52af28ec0c4fcf2ef38ff9c31b10fbc to your computer and use it in GitHub Desktop.
Save Neradoc/b52af28ec0c4fcf2ef38ff9c31b10fbc to your computer and use it in GitHub Desktop.
Micropython test for neopixels with arguments using "ampy run".
import time,sys
from machine import Pin
from neopixel import NeoPixel
color = [0,64,64]
if len(sys.argv) >= 4:
try:
col = [int(sys.argv[1]),int(sys.argv[2]),int(sys.argv[3])]
color = col
except:
print("Color invalid")
print("Usage: [R G B [NPixels]]")
sys.exit()
NPIXELS = 64
if len(sys.argv) >= 5:
try:
NPIX = int(sys.argv[4])
NPIXELS = NPIX
except:
print("Number of pixels invalid")
print("Usage: [R G B [NPixels]]")
sys.exit()
monPixel = NeoPixel(Pin(14), NPIXELS)
monPixel.fill((0,0,0))
monPixel.write()
pixels = [x for x in range(0,NPIXELS)]
pixels += [x for x in range(0,NPIXELS-1)][::-1]
for pix in pixels:
if pix>0:
monPixel[pix-1] = (0,0,0)
monPixel[pix] = color
monPixel.write()
time.sleep_ms(100)
for pix in [x for x in range(0,NPIXELS)][::-1]:
monPixel[pix] = (0,0,0)
monPixel.write()
time.sleep_ms(100)
for pix in [x for x in range(0,int(NPIXELS/2)+1)]:
monPixel[pix] = color
monPixel[NPIXELS-pix-1] = color
monPixel.write()
time.sleep_ms(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment