Format superhero power plant
This commit is contained in:
parent
6558031f90
commit
319c507a38
1 changed files with 25 additions and 25 deletions
|
|
@ -1,36 +1,36 @@
|
||||||
import board
|
import board
|
||||||
import neopixel
|
import neopixel
|
||||||
import time
|
|
||||||
try:
|
try:
|
||||||
import urandom as random # for v1.0 API support
|
import urandom as random # for v1.0 API support
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import random
|
import random
|
||||||
|
|
||||||
numpix = 17 # Number of NeoPixels
|
num_pix = 17 # Number of NeoPixels
|
||||||
pixpin = board.D1 # Pin where NeoPixels are connected
|
pix_pin = board.D1 # Pin where NeoPixels are connected
|
||||||
strip = neopixel.NeoPixel(pixpin, numpix)
|
strip = neopixel.NeoPixel(pix_pin, num_pix)
|
||||||
|
|
||||||
minAlpha = 0.1 # Minimum brightness
|
min_alpha = 0.1 # Minimum brightness
|
||||||
maxAlpha = 0.4 # Maximum brightness
|
max_alpha = 0.4 # Maximum brightness
|
||||||
alpha = (minAlpha + maxAlpha) / 2 # Start in middle
|
alpha = (min_alpha + max_alpha) / 2 # Start in middle
|
||||||
alphaDelta = 0.01 # Amount to change brightness each time through loop
|
alpha_delta = 0.01 # Amount to change brightness each time through loop
|
||||||
alphaUp = True # If True, brightness increasing, else decreasing
|
alpha_up = True # If True, brightness increasing, else decreasing
|
||||||
|
|
||||||
strip.fill([0, 0, 255]) # Fill blue, or change to R,G,B of your liking
|
strip.fill([0, 0, 255]) # Fill blue, or change to R,G,B of your liking
|
||||||
|
|
||||||
while True: # Loop forever...
|
while True: # Loop forever...
|
||||||
if random.randint(1, 5) == 5: # 1-in-5 random chance
|
if random.randint(1, 5) == 5: # 1-in-5 random chance
|
||||||
alphaUp = not alphaUp # of reversing direction
|
alpha_up = not alpha_up # of reversing direction
|
||||||
if alphaUp: # Increasing brightness?
|
if alpha_up: # Increasing brightness?
|
||||||
alpha += alphaDelta # Add some amount
|
alpha += alpha_delta # Add some amount
|
||||||
if alpha >= maxAlpha: # At or above max?
|
if alpha >= max_alpha: # At or above max?
|
||||||
alpha = maxAlpha # Limit to max
|
alpha = max_alpha # Limit to max
|
||||||
alphaUp = False # and switch direction
|
alpha_up = False # and switch direction
|
||||||
else: # Else decreasing brightness
|
else: # Else decreasing brightness
|
||||||
alpha -= alphaDelta # Subtract some amount
|
alpha -= alpha_delta # Subtract some amount
|
||||||
if alpha <= minAlpha: # At or below min?
|
if alpha <= min_alpha: # At or below min?
|
||||||
alpha = minAlpha # Limit to min
|
alpha = min_alpha # Limit to min
|
||||||
alphaUp = True # and switch direction
|
alpha_up = True # and switch direction
|
||||||
|
|
||||||
strip.brightness = alpha # Set brightness to 0.0 to 1.0
|
strip.brightness = alpha # Set brightness to 0.0 to 1.0
|
||||||
strip.write() # and issue data to LED strip
|
strip.write() # and issue data to LED strip
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue