Skip to content

Instantly share code, notes, and snippets.

@danmaps
Created March 11, 2020 20:22
Show Gist options
  • Save danmaps/3639a6db9539227ddfc6593e7f5591f8 to your computer and use it in GitHub Desktop.
Save danmaps/3639a6db9539227ddfc6593e7f5591f8 to your computer and use it in GitHub Desktop.
blink leds on circuit python playground
# blinky vs blinky_gap
# inspired by https://learn.adafruit.com/sipping-power-with-neopixels?view=all
import time
from adafruit_circuitplayground import cp
cp.pixels.brightness = .004
def blinky(color,t=1):
t = t/10
for pix in range(10):
cp.pixels[pix] = color
time.sleep(t)
cp.pixels[pix] = (0,0,0)
def blinky_gap(color,t=1):
t = t/12 # default sleep time is 1/12 seconds
for pix in range(12):
# i = pix + (pix > 4)
# print(pix, i,)
# time.sleep(t)
if pix == 5 or pix == 11:
time.sleep(t)
else:
if pix <5:
cp.pixels[pix] = color
time.sleep(t)
cp.pixels[pix] = (0,0,0)
else:
cp.pixels[pix-1] = color
time.sleep(t)
cp.pixels[pix-1] = (0,0,0)
while True:
if cp.switch:
blinky_gap((0, 0, 255),1)
# time.sleep(1)
else:
blinky((255, 255, 255),1)
# time.sleep(1)
#time.sleep(0.01) # debounce delay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment