Autformat the rest
This commit is contained in:
parent
1350a433a7
commit
aecc9347c9
15 changed files with 164 additions and 115 deletions
|
|
@ -7,30 +7,67 @@
|
||||||
# License: MIT License (https://opensource.org/licenses/MIT)
|
# License: MIT License (https://opensource.org/licenses/MIT)
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import board
|
import board
|
||||||
import neopixel
|
import neopixel
|
||||||
|
|
||||||
# Configuration:
|
# Configuration:
|
||||||
# Message to display (capital letters and numbers only)
|
# Message to display (capital letters and numbers only)
|
||||||
message = 'SOS'
|
message = 'SOS'
|
||||||
dot_length = 0.15 # Duration of one Morse dot
|
dot_length = 0.15 # Duration of one Morse dot
|
||||||
dash_length = (dot_length * 3.0) # Duration of one Morse dash
|
dash_length = (dot_length * 3.0) # Duration of one Morse dash
|
||||||
symbol_gap = dot_length # Duration of gap between dot or dash
|
symbol_gap = dot_length # Duration of gap between dot or dash
|
||||||
character_gap = (dot_length * 3.0) # Duration of gap between characters
|
character_gap = (dot_length * 3.0) # Duration of gap between characters
|
||||||
flash_color = (255, 0, 0) # Color of the morse display.
|
flash_color = (255, 0, 0) # Color of the morse display.
|
||||||
brightness = 0.5 # Display brightness (0.0 - 1.0)
|
brightness = 0.5 # Display brightness (0.0 - 1.0)
|
||||||
morse = [('A', '.-'), ('B', '-...'), ('C', '-.-.'), ('D', '-..'), ('E', '.'), ('F', '..-.'), ('G', '--.'), ('H', '....'), ('I', '..'), ('J', '.---'), ('K', '-.-'), ('L', '.-..'), ('M', '--'), ('N', '-.'), ('O', '---'), ('P', '.--.'), ('Q', '--.-'), ('R', '.-.'), ('S',
|
morse = [
|
||||||
'...'), ('T', '-'), ('U', '..-'), ('V', '...-'), ('W', '.--'), ('X', '-..-'), ('Y', '-.--'), ('Z', '--..'), ('0', '-----'), ('1', '.----'), ('2', '..---'), ('3', '...--'), ('4', '....-'), ('5', '.....'), ('6', '-....'), ('7', '--...'), ('8', '---..'), ('9', '----.')]
|
('A', '.-'),
|
||||||
|
('B', '-...'),
|
||||||
|
('C', '-.-.'),
|
||||||
|
('D', '-..'),
|
||||||
|
('E', '.'),
|
||||||
|
('F', '..-.'),
|
||||||
|
('G', '--.'),
|
||||||
|
('H', '....'),
|
||||||
|
('I', '..'),
|
||||||
|
('J', '.---'),
|
||||||
|
('K', '-.-'),
|
||||||
|
('L', '.-..'),
|
||||||
|
('M', '--'),
|
||||||
|
('N', '-.'),
|
||||||
|
('O', '---'),
|
||||||
|
('P', '.--.'),
|
||||||
|
('Q', '--.-'),
|
||||||
|
('R', '.-.'),
|
||||||
|
('S', '...'),
|
||||||
|
('T', '-'),
|
||||||
|
('U', '..-'),
|
||||||
|
('V', '...-'),
|
||||||
|
('W', '.--'),
|
||||||
|
('X', '-..-'),
|
||||||
|
('Y', '-.--'),
|
||||||
|
('Z', '--..'),
|
||||||
|
('0', '-----'),
|
||||||
|
('1', '.----'),
|
||||||
|
('2', '..---'),
|
||||||
|
('3', '...--'),
|
||||||
|
('4', '....-'),
|
||||||
|
('5', '.....'),
|
||||||
|
('6', '-....'),
|
||||||
|
('7', '--...'),
|
||||||
|
('8', '---..'),
|
||||||
|
('9', '----.'),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
# Define a class that represents the morse flasher.
|
# Define a class that represents the morse flasher.
|
||||||
|
|
||||||
|
|
||||||
class MorseFlasher:
|
class MorseFlasher:
|
||||||
|
|
||||||
def __init__(self, color=(255, 255, 255)):
|
def __init__(self, color=(255, 255, 255)):
|
||||||
# set the color adjusted for brightness
|
# set the color adjusted for brightness
|
||||||
self._color = (
|
self._color = (
|
||||||
int(color[0]*brightness), int(color[1]*brightness), int(color[2]*brightness))
|
int(color[0] * brightness), int(color[1] * brightness), int(color[2] * brightness))
|
||||||
|
|
||||||
def light(self, on=True):
|
def light(self, on=True):
|
||||||
if on:
|
if on:
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
import board
|
|
||||||
import time
|
import time
|
||||||
import pulseio
|
|
||||||
from digitalio import DigitalInOut, Direction, Pull
|
|
||||||
from analogio import AnalogIn
|
|
||||||
import adafruit_motor.servo
|
import adafruit_motor.servo
|
||||||
|
import board
|
||||||
|
import pulseio
|
||||||
|
from analogio import AnalogIn
|
||||||
|
from digitalio import DigitalInOut, Direction, Pull
|
||||||
|
|
||||||
pwm = pulseio.PWMOut(board.D5, frequency=50)
|
pwm = pulseio.PWMOut(board.D5, frequency=50)
|
||||||
servo = adafruit_motor.servo.Servo(pwm)
|
servo = adafruit_motor.servo.Servo(pwm)
|
||||||
|
|
|
||||||
|
|
@ -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
|
numpix = 17 # Number of NeoPixels
|
||||||
pixpin = board.D1 # Pin where NeoPixels are connected
|
pixpin = board.D1 # Pin where NeoPixels are connected
|
||||||
strip = neopixel.NeoPixel(pixpin, numpix)
|
strip = neopixel.NeoPixel(pixpin, numpix)
|
||||||
|
|
||||||
minAlpha = 0.1 # Minimum brightness
|
minAlpha = 0.1 # Minimum brightness
|
||||||
maxAlpha = 0.4 # Maximum brightness
|
maxAlpha = 0.4 # Maximum brightness
|
||||||
alpha = (minAlpha + maxAlpha) / 2 # Start in middle
|
alpha = (minAlpha + maxAlpha) / 2 # Start in middle
|
||||||
alphaDelta = 0.008 # Amount to change brightness each time through loop
|
alphaDelta = 0.008 # Amount to change brightness each time through loop
|
||||||
alphaUp = True # If True, brightness increasing, else decreasing
|
alphaUp = True # If True, brightness increasing, else decreasing
|
||||||
|
|
||||||
strip.fill([255, 0, 0]) # Fill red, or change to R,G,B of your liking
|
strip.fill([255, 0, 0]) # Fill red, 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
|
alphaUp = not alphaUp # of reversing direction
|
||||||
if alphaUp: # Increasing brightness?
|
if alphaUp: # Increasing brightness?
|
||||||
alpha += alphaDelta # Add some amount
|
alpha += alphaDelta # Add some amount
|
||||||
if alpha >= maxAlpha: # At or above max?
|
if alpha >= maxAlpha: # At or above max?
|
||||||
alpha = maxAlpha # Limit to max
|
alpha = maxAlpha # Limit to max
|
||||||
alphaUp = False # and switch direction
|
alphaUp = False # and switch direction
|
||||||
else: # Else decreasing brightness
|
else: # Else decreasing brightness
|
||||||
alpha -= alphaDelta # Subtract some amount
|
alpha -= alphaDelta # Subtract some amount
|
||||||
if alpha <= minAlpha: # At or below min?
|
if alpha <= minAlpha: # At or below min?
|
||||||
alpha = minAlpha # Limit to min
|
alpha = minAlpha # Limit to min
|
||||||
alphaUp = True # and switch direction
|
alphaUp = 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
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,34 @@
|
||||||
|
import time
|
||||||
|
|
||||||
|
import analogio
|
||||||
import board
|
import board
|
||||||
import digitalio
|
import digitalio
|
||||||
import analogio
|
|
||||||
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:
|
except:
|
||||||
import random
|
import random
|
||||||
|
|
||||||
num_leds = 24 # 24 LED NeoPixel ring
|
num_leds = 24 # 24 LED NeoPixel ring
|
||||||
neopixel_pin = board.D0 # Pin where NeoPixels are connected
|
neopixel_pin = board.D0 # Pin where NeoPixels are connected
|
||||||
vibration_pin = board.D1 # Pin where vibration switch is connected
|
vibration_pin = board.D1 # Pin where vibration switch is connected
|
||||||
analog_pin = board.A0 # Not connected to anything
|
analog_pin = board.A0 # Not connected to anything
|
||||||
strip = neopixel.NeoPixel(neopixel_pin, num_leds)
|
strip = neopixel.NeoPixel(neopixel_pin, num_leds)
|
||||||
|
|
||||||
default_frame_len = 0.06 # Time (in seconds) of typical animation frame
|
default_frame_len = 0.06 # Time (in seconds) of typical animation frame
|
||||||
max_frame_len = 0.25 # Gradually slows toward this
|
max_frame_len = 0.25 # Gradually slows toward this
|
||||||
min_frame_len = 0.005 # But sometimes as little as this
|
min_frame_len = 0.005 # But sometimes as little as this
|
||||||
cooldown_at = 2.0 # After this many seconds, start slowing down
|
cooldown_at = 2.0 # After this many seconds, start slowing down
|
||||||
dim_at = 2.5 # After this many seconds, dim LEDs
|
dim_at = 2.5 # After this many seconds, dim LEDs
|
||||||
brightness_high = 0.5 # Active brightness
|
brightness_high = 0.5 # Active brightness
|
||||||
brightness_low = 0.125 # Idle brightness
|
brightness_low = 0.125 # Idle brightness
|
||||||
|
|
||||||
color = [0, 120, 30] # Initial LED color
|
color = [0, 120, 30] # Initial LED color
|
||||||
offset = 0 # Animation position
|
offset = 0 # Animation position
|
||||||
frame_len = default_frame_len # Frame-to-frame time, seconds
|
frame_len = default_frame_len # Frame-to-frame time, seconds
|
||||||
last_vibration = 0.0 # Time of last vibration
|
last_vibration = 0.0 # Time of last vibration
|
||||||
last_frame = 0.0 # Time of last animation frame
|
last_frame = 0.0 # Time of last animation frame
|
||||||
|
|
||||||
# Random number generator is seeded from an unused 'floating'
|
# Random number generator is seeded from an unused 'floating'
|
||||||
# analog input - this helps ensure the random color choices
|
# analog input - this helps ensure the random color choices
|
||||||
|
|
@ -55,10 +57,10 @@ while True: # Loop forever...
|
||||||
random.randint(32, 255),
|
random.randint(32, 255),
|
||||||
random.randint(32, 255)]
|
random.randint(32, 255)]
|
||||||
frame_len = default_frame_len # Reset frame timing
|
frame_len = default_frame_len # Reset frame timing
|
||||||
last_vibration = t # Save last trigger time
|
last_vibration = t # Save last trigger time
|
||||||
|
|
||||||
# Stretch out frames if nothing has happened in a couple of seconds:
|
# Stretch out frames if nothing has happened in a couple of seconds:
|
||||||
if((t - last_vibration) > cooldown_at):
|
if ((t - last_vibration) > cooldown_at):
|
||||||
frame_len += 0.001 # Add 1 ms
|
frame_len += 0.001 # Add 1 ms
|
||||||
if frame_len > max_frame_len:
|
if frame_len > max_frame_len:
|
||||||
frame_len = min_frame_len
|
frame_len = min_frame_len
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
import time
|
import time
|
||||||
from analogio import AnalogIn
|
|
||||||
|
import adafruit_character_lcd
|
||||||
import adafruit_fancyled.adafruit_fancyled as fancy
|
import adafruit_fancyled.adafruit_fancyled as fancy
|
||||||
import board
|
import board
|
||||||
import digitalio
|
import digitalio
|
||||||
import adafruit_character_lcd
|
|
||||||
import neopixel
|
import neopixel
|
||||||
|
from analogio import AnalogIn
|
||||||
|
|
||||||
lcd_rs = digitalio.DigitalInOut(board.D5)
|
lcd_rs = digitalio.DigitalInOut(board.D5)
|
||||||
lcd_en = digitalio.DigitalInOut(board.D6)
|
lcd_en = digitalio.DigitalInOut(board.D6)
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
import time
|
|
||||||
import math
|
import math
|
||||||
from analogio import AnalogIn
|
import time
|
||||||
|
|
||||||
|
import adafruit_character_lcd
|
||||||
import board
|
import board
|
||||||
import digitalio
|
import digitalio
|
||||||
import adafruit_character_lcd
|
|
||||||
import neopixel
|
import neopixel
|
||||||
|
from analogio import AnalogIn
|
||||||
|
|
||||||
lcd_rs = digitalio.DigitalInOut(board.D5)
|
lcd_rs = digitalio.DigitalInOut(board.D5)
|
||||||
lcd_en = digitalio.DigitalInOut(board.D6)
|
lcd_en = digitalio.DigitalInOut(board.D6)
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
from analogio import AnalogIn
|
|
||||||
import board
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
import board
|
||||||
import neopixel
|
import neopixel
|
||||||
|
from analogio import AnalogIn
|
||||||
|
|
||||||
pot = AnalogIn(board.A1) # what pin the pot is on
|
pot = AnalogIn(board.A1) # what pin the pot is on
|
||||||
pixpin = board.D0 # what pin the LEDs are on
|
pixpin = board.D0 # what pin the LEDs are on
|
||||||
numpix = 16 # number of LEDs in ring!
|
numpix = 16 # number of LEDs in ring!
|
||||||
BPP = 4 # required for RGBW ring
|
BPP = 4 # required for RGBW ring
|
||||||
|
|
||||||
ring = neopixel.NeoPixel(pixpin, numpix, bpp=BPP, brightness=0.9)
|
ring = neopixel.NeoPixel(pixpin, numpix, bpp=BPP, brightness=0.9)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
|
import time
|
||||||
|
|
||||||
import board
|
import board
|
||||||
import neopixel
|
import neopixel
|
||||||
import time
|
|
||||||
|
|
||||||
pixpin = board.D1
|
pixpin = board.D1
|
||||||
numpix = 7
|
numpix = 7
|
||||||
|
|
@ -11,9 +12,9 @@ rgb_colors = ([179, 0, 0],
|
||||||
[0, 179, 0],
|
[0, 179, 0],
|
||||||
[0, 0, 0])
|
[0, 0, 0])
|
||||||
|
|
||||||
rgb_idx = 0 # index counter - primary color we are on
|
rgb_idx = 0 # index counter - primary color we are on
|
||||||
color = (0, 164, 179) # Starting color
|
color = (0, 164, 179) # Starting color
|
||||||
mode = 0 # Current animation effect
|
mode = 0 # Current animation effect
|
||||||
offset = 0
|
offset = 0
|
||||||
prevtime = 0
|
prevtime = 0
|
||||||
|
|
||||||
|
|
@ -24,17 +25,17 @@ def wheel(pos):
|
||||||
if (pos < 0) or (pos > 255):
|
if (pos < 0) or (pos > 255):
|
||||||
return (0, 0, 0)
|
return (0, 0, 0)
|
||||||
if (pos < 85):
|
if (pos < 85):
|
||||||
return (int(pos * 3), int(255 - (pos*3)), 0)
|
return (int(pos * 3), int(255 - (pos * 3)), 0)
|
||||||
elif (pos < 170):
|
elif (pos < 170):
|
||||||
pos -= 85
|
pos -= 85
|
||||||
return (int(255 - pos*3), 0, int(pos*3))
|
return (int(255 - pos * 3), 0, int(pos * 3))
|
||||||
else:
|
else:
|
||||||
pos -= 170
|
pos -= 170
|
||||||
return (0, int(pos*3), int(255 - pos*3))
|
return (0, int(pos * 3), int(255 - pos * 3))
|
||||||
|
|
||||||
|
|
||||||
def rainbow_cycle(wait):
|
def rainbow_cycle(wait):
|
||||||
for j in range(255*6): # 6 cycles of all colors on wheel
|
for j in range(255 * 6): # 6 cycles of all colors on wheel
|
||||||
for r in range(len(pixels)):
|
for r in range(len(pixels)):
|
||||||
idx = int((r * 255 / len(pixels)) + j)
|
idx = int((r * 255 / len(pixels)) + j)
|
||||||
pixels[r] = wheel(idx & 255)
|
pixels[r] = wheel(idx & 255)
|
||||||
|
|
@ -45,14 +46,14 @@ def rainbow_cycle(wait):
|
||||||
def rainbow(wait):
|
def rainbow(wait):
|
||||||
for j in range(255):
|
for j in range(255):
|
||||||
for i in range(len(pixels)):
|
for i in range(len(pixels)):
|
||||||
idx = int(i+j)
|
idx = int(i + j)
|
||||||
pixels[i] = wheel(idx & 255)
|
pixels[i] = wheel(idx & 255)
|
||||||
pixels.write()
|
pixels.write()
|
||||||
time.sleep(wait)
|
time.sleep(wait)
|
||||||
|
|
||||||
|
|
||||||
def rainbow_cycle_slow(wait):
|
def rainbow_cycle_slow(wait):
|
||||||
for j in range(255*3): # 3 cycles of all colors on wheel
|
for j in range(255 * 3): # 3 cycles of all colors on wheel
|
||||||
for r in range(len(pixels)):
|
for r in range(len(pixels)):
|
||||||
idx = int((r * 255 / len(pixels)) + j)
|
idx = int((r * 255 / len(pixels)) + j)
|
||||||
pixels[r] = wheel(idx & 255)
|
pixels[r] = wheel(idx & 255)
|
||||||
|
|
@ -61,7 +62,7 @@ def rainbow_cycle_slow(wait):
|
||||||
|
|
||||||
|
|
||||||
def rainbow_hold(wait):
|
def rainbow_hold(wait):
|
||||||
for j in range(255*1): # 3 cycles of all colors on wheel
|
for j in range(255 * 1): # 3 cycles of all colors on wheel
|
||||||
for r in range(len(pixels)):
|
for r in range(len(pixels)):
|
||||||
idx = int((r * 255 / len(pixels)) + j)
|
idx = int((r * 255 / len(pixels)) + j)
|
||||||
pixels[r] = wheel(idx & 255)
|
pixels[r] = wheel(idx & 255)
|
||||||
|
|
@ -71,26 +72,26 @@ def rainbow_hold(wait):
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
if (mode == 0): # rainbow hold
|
if (mode == 0): # rainbow hold
|
||||||
rainbow_hold(0.02)
|
rainbow_hold(0.02)
|
||||||
time.sleep(.5)
|
time.sleep(.5)
|
||||||
|
|
||||||
elif (mode == 1): # rainbow cycle slow
|
elif (mode == 1): # rainbow cycle slow
|
||||||
rainbow_cycle_slow(0.02)
|
rainbow_cycle_slow(0.02)
|
||||||
time.sleep(0.05)
|
time.sleep(0.05)
|
||||||
|
|
||||||
elif (mode == 2): # rainbow cycle fast
|
elif (mode == 2): # rainbow cycle fast
|
||||||
rainbow_cycle(0.005)
|
rainbow_cycle(0.005)
|
||||||
time.sleep(0.050)
|
time.sleep(0.050)
|
||||||
|
|
||||||
t = time.monotonic()
|
t = time.monotonic()
|
||||||
|
|
||||||
if ((t - prevtime) > 8): # Every 8 seconds...
|
if ((t - prevtime) > 8): # Every 8 seconds...
|
||||||
mode += 1 # Next mode
|
mode += 1 # Next mode
|
||||||
if(mode > 2): # End of modes?
|
if (mode > 2): # End of modes?
|
||||||
mode = 0 # Start modes over
|
mode = 0 # Start modes over
|
||||||
|
|
||||||
if (rgb_idx > 2): # reset R-->G-->B rotation
|
if (rgb_idx > 2): # reset R-->G-->B rotation
|
||||||
rgb_idx = 0
|
rgb_idx = 0
|
||||||
|
|
||||||
color = rgb_colors[rgb_idx] # next color assignment
|
color = rgb_colors[rgb_idx] # next color assignment
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
from digitalio import DigitalInOut, Direction
|
import time
|
||||||
|
|
||||||
import board
|
import board
|
||||||
import neopixel
|
import neopixel
|
||||||
import time
|
from digitalio import DigitalInOut, Direction
|
||||||
|
|
||||||
pixpin = board.D1
|
pixpin = board.D1
|
||||||
numpix = 5
|
numpix = 5
|
||||||
|
|
@ -24,13 +25,13 @@ def wheel(pos):
|
||||||
if (pos < 0) or (pos > 255):
|
if (pos < 0) or (pos > 255):
|
||||||
return (0, 0, 0)
|
return (0, 0, 0)
|
||||||
if (pos < 85):
|
if (pos < 85):
|
||||||
return (int(pos * 3), int(255 - (pos*3)), 0)
|
return (int(pos * 3), int(255 - (pos * 3)), 0)
|
||||||
elif (pos < 170):
|
elif (pos < 170):
|
||||||
pos -= 85
|
pos -= 85
|
||||||
return (int(255 - pos*3), 0, int(pos*3))
|
return (int(255 - pos * 3), 0, int(pos * 3))
|
||||||
else:
|
else:
|
||||||
pos -= 170
|
pos -= 170
|
||||||
return (0, int(pos*3), int(255 - pos*3))
|
return (0, int(pos * 3), int(255 - pos * 3))
|
||||||
|
|
||||||
|
|
||||||
def rainbow_cycle(wait):
|
def rainbow_cycle(wait):
|
||||||
|
|
@ -44,12 +45,11 @@ def rainbow_cycle(wait):
|
||||||
def rainbow(wait):
|
def rainbow(wait):
|
||||||
for j in range(255):
|
for j in range(255):
|
||||||
for i in range(len(strip)):
|
for i in range(len(strip)):
|
||||||
idx = int(i+j)
|
idx = int(i + j)
|
||||||
strip[i] = wheel(idx & 255)
|
strip[i] = wheel(idx & 255)
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
colorWipe((255, 0, 0), .1) # red and delay
|
colorWipe((255, 0, 0), .1) # red and delay
|
||||||
colorWipe((0, 255, 0), .1) # green and delay
|
colorWipe((0, 255, 0), .1) # green and delay
|
||||||
colorWipe((0, 0, 255), .1) # blue and delay
|
colorWipe((0, 0, 255), .1) # blue and delay
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,23 @@
|
||||||
|
import time
|
||||||
|
|
||||||
import board
|
import board
|
||||||
import neopixel
|
import neopixel
|
||||||
import time
|
|
||||||
try:
|
try:
|
||||||
import urandom as random
|
import urandom as random
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import random
|
import random
|
||||||
|
|
||||||
numpix = 64 # Number of NeoPixels
|
numpix = 64 # Number of NeoPixels
|
||||||
pixpin = board.D1 # Pin where NeoPixels are connected
|
pixpin = board.D1 # Pin where NeoPixels are connected
|
||||||
strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.15)
|
strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.15)
|
||||||
color = [5, 250, 200] # RGB color - cyan
|
color = [5, 250, 200] # RGB color - cyan
|
||||||
|
|
||||||
sine = [ # These are the pixels in order of animation - 70 pixels in total:
|
sine = [ # These are the pixels in order of animation - 70 pixels in total:
|
||||||
4, 3, 2, 1, 0, 15, 14, 13, 12, 20, 21, 22, 23, 24, 25, 26, 27, 28,
|
4, 3, 2, 1, 0, 15, 14, 13, 12, 20, 21, 22, 23, 24, 25, 26, 27, 28,
|
||||||
36, 35, 34, 33, 32, 47, 46, 45, 44, 52, 53, 54, 55, 56, 57, 58, 59, 60,
|
36, 35, 34, 33, 32, 47, 46, 45, 44, 52, 53, 54, 55, 56, 57, 58, 59, 60,
|
||||||
61, 62, 63, 48, 49, 50, 51, 52, 44, 43, 42, 41, 40, 39, 38, 37, 36, 28,
|
61, 62, 63, 48, 49, 50, 51, 52, 44, 43, 42, 41, 40, 39, 38, 37, 36, 28,
|
||||||
29, 30, 31, 16, 17, 18, 19, 20, 12, 11, 10, 9, 8, 7, 6, 5]
|
29, 30, 31, 16, 17, 18, 19, 20, 12, 11, 10, 9, 8, 7, 6, 5]
|
||||||
|
|
||||||
while True: # Loop forever...
|
while True: # Loop forever...
|
||||||
for i in range(len(sine)):
|
for i in range(len(sine)):
|
||||||
|
|
@ -23,5 +25,5 @@ while True: # Loop forever...
|
||||||
strip[sine[i]] = [0, 0, 0]
|
strip[sine[i]] = [0, 0, 0]
|
||||||
# Draw 'head,' 10 pixels ahead:
|
# Draw 'head,' 10 pixels ahead:
|
||||||
strip[sine[(i + 10) % len(sine)]] = color
|
strip[sine[(i + 10) % len(sine)]] = color
|
||||||
strip.write() # Refresh LED states
|
strip.write() # Refresh LED states
|
||||||
time.sleep(0.04) # 40 millisecond delay
|
time.sleep(0.04) # 40 millisecond delay
|
||||||
|
|
|
||||||
|
|
@ -1,28 +1,28 @@
|
||||||
import board
|
import board
|
||||||
import neopixel
|
import neopixel
|
||||||
import time
|
|
||||||
try:
|
try:
|
||||||
import urandom as random
|
import urandom as random
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import random
|
import random
|
||||||
|
|
||||||
numpix = 64 # Number of NeoPixels
|
numpix = 64 # Number of NeoPixels
|
||||||
pixpin = board.D1 # Pin where NeoPixels are connected
|
pixpin = board.D1 # Pin where NeoPixels are connected
|
||||||
strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.0)
|
strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.0)
|
||||||
colors = [
|
colors = [
|
||||||
[232, 100, 255], # Purple
|
[232, 100, 255], # Purple
|
||||||
[200, 200, 20], # Yellow
|
[200, 200, 20], # Yellow
|
||||||
[30, 200, 200], # Blue
|
[30, 200, 200], # Blue
|
||||||
]
|
]
|
||||||
|
|
||||||
while True: # Loop forever...
|
while True: # Loop forever...
|
||||||
c = random.randint(0, len(colors) - 1) # Choose random color index
|
c = random.randint(0, len(colors) - 1) # Choose random color index
|
||||||
j = random.randint(0, numpix - 1) # Choose random pixel
|
j = random.randint(0, numpix - 1) # Choose random pixel
|
||||||
strip[j] = colors[c] # Set pixel to color
|
strip[j] = colors[c] # Set pixel to color
|
||||||
for i in range(1, 5):
|
for i in range(1, 5):
|
||||||
strip.brightness = i / 5.0 # Ramp up brightness
|
strip.brightness = i / 5.0 # Ramp up brightness
|
||||||
strip.write()
|
strip.write()
|
||||||
for i in range(5, 0, -1):
|
for i in range(5, 0, -1):
|
||||||
strip.brightness = i / 5.0 # Ramp down brightness
|
strip.brightness = i / 5.0 # Ramp down brightness
|
||||||
strip.write()
|
strip.write()
|
||||||
strip[j] = [0, 0, 0] # Set pixel to 'off'
|
strip[j] = [0, 0, 0] # Set pixel to 'off'
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,20 @@
|
||||||
|
import time
|
||||||
|
|
||||||
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 = 64 # Number of NeoPixels
|
numpix = 64 # Number of NeoPixels
|
||||||
pixpin = board.D1 # Pin where NeoPixels are connected
|
pixpin = board.D1 # Pin where NeoPixels are connected
|
||||||
strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.15)
|
strip = neopixel.NeoPixel(pixpin, numpix, brightness=0.15)
|
||||||
color = [75, 250, 100] # RGB color - teal
|
color = [75, 250, 100] # RGB color - teal
|
||||||
|
|
||||||
sine = [ # These are the pixels in order of animation - 36 pixels in total:
|
sine = [ # These are the pixels in order of animation - 36 pixels in total:
|
||||||
4, 3, 2, 1, 0, 15, 14, 13, 12, 20, 21, 22, 23, 24, 25, 26, 27, 28,
|
4, 3, 2, 1, 0, 15, 14, 13, 12, 20, 21, 22, 23, 24, 25, 26, 27, 28,
|
||||||
36, 35, 34, 33, 32, 47, 46, 45, 44, 52, 53, 54, 55, 56, 57, 58, 59, 60]
|
36, 35, 34, 33, 32, 47, 46, 45, 44, 52, 53, 54, 55, 56, 57, 58, 59, 60]
|
||||||
|
|
||||||
while True: # Loop forever...
|
while True: # Loop forever...
|
||||||
|
|
@ -21,5 +23,5 @@ while True: # Loop forever...
|
||||||
strip[sine[i]] = color
|
strip[sine[i]] = color
|
||||||
# Erase 'tail,' 8 pixels back:
|
# Erase 'tail,' 8 pixels back:
|
||||||
strip[sine[(i + len(sine) - 8) % len(sine)]] = [0, 0, 0]
|
strip[sine[(i + len(sine) - 8) % len(sine)]] = [0, 0, 0]
|
||||||
strip.write() # Refresh LED states
|
strip.write() # Refresh LED states
|
||||||
time.sleep(0.016) # 16 millisecond delay
|
time.sleep(0.016) # 16 millisecond delay
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,37 @@
|
||||||
|
import time
|
||||||
|
|
||||||
import board
|
import board
|
||||||
import neopixel
|
import neopixel
|
||||||
import time
|
|
||||||
try:
|
try:
|
||||||
import urandom as random
|
import urandom as random
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import random
|
import random
|
||||||
|
|
||||||
numpix = 7 # Number of NeoPixels
|
numpix = 7 # Number of NeoPixels
|
||||||
pixpin = board.D1 # Pin where NeoPixels are connected
|
pixpin = board.D1 # Pin where NeoPixels are connected
|
||||||
strip = neopixel.NeoPixel(pixpin, numpix, brightness=1, auto_write=True)
|
strip = neopixel.NeoPixel(pixpin, numpix, brightness=1, auto_write=True)
|
||||||
colors = [
|
colors = [
|
||||||
[232, 100, 255], # Purple
|
[232, 100, 255], # Purple
|
||||||
[200, 200, 20], # Yellow
|
[200, 200, 20], # Yellow
|
||||||
[30, 200, 200], # Blue
|
[30, 200, 200], # Blue
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
def flash_random(wait, howmany):
|
def flash_random(wait, howmany):
|
||||||
|
|
||||||
for k in range(howmany):
|
for k in range(howmany):
|
||||||
|
|
||||||
c = random.randint(0, len(colors) - 1) # Choose random color index
|
c = random.randint(0, len(colors) - 1) # Choose random color index
|
||||||
j = random.randint(0, numpix - 1) # Choose random pixel
|
j = random.randint(0, numpix - 1) # Choose random pixel
|
||||||
strip[j] = colors[c] # Set pixel to color
|
strip[j] = colors[c] # Set pixel to color
|
||||||
|
|
||||||
for i in range(1, 5):
|
for i in range(1, 5):
|
||||||
strip.brightness = i / 5.0 # Ramp up brightness
|
strip.brightness = i / 5.0 # Ramp up brightness
|
||||||
time.sleep(wait)
|
time.sleep(wait)
|
||||||
|
|
||||||
for i in range(5, 0, -1):
|
for i in range(5, 0, -1):
|
||||||
strip.brightness = i / 5.0 # Ramp down brightness
|
strip.brightness = i / 5.0 # Ramp down brightness
|
||||||
strip[j] = [0, 0, 0] # Set pixel to 'off'
|
strip[j] = [0, 0, 0] # Set pixel to 'off'
|
||||||
time.sleep(wait)
|
time.sleep(wait)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
from digitalio import DigitalInOut, Direction
|
|
||||||
import board
|
import board
|
||||||
import busio
|
import busio
|
||||||
import time
|
from digitalio import DigitalInOut, Direction
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import struct
|
import struct
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
@ -26,7 +26,7 @@ while True:
|
||||||
buffer.pop(0)
|
buffer.pop(0)
|
||||||
|
|
||||||
if len(buffer) > 200:
|
if len(buffer) > 200:
|
||||||
buffer = [] # avoid an overrun if all bad data
|
buffer = [] # avoid an overrun if all bad data
|
||||||
if len(buffer) < 32:
|
if len(buffer) < 32:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
@ -66,4 +66,4 @@ while True:
|
||||||
print("---------------------------------------")
|
print("---------------------------------------")
|
||||||
|
|
||||||
buffer = buffer[32:]
|
buffer = buffer[32:]
|
||||||
#print("Buffer ", buffer)
|
# print("Buffer ", buffer)
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ while True:
|
||||||
except adafruit_irremote.IRNECRepeatException: # unusual short code!
|
except adafruit_irremote.IRNECRepeatException: # unusual short code!
|
||||||
print("NEC repeat!")
|
print("NEC repeat!")
|
||||||
command = last_command
|
command = last_command
|
||||||
except adafruit_irremote.IRDecodeException as e: # failed to decode
|
except adafruit_irremote.IRDecodeException as e: # failed to decode
|
||||||
print("Failed to decode:", e)
|
print("Failed to decode:", e)
|
||||||
except MemoryError as e:
|
except MemoryError as e:
|
||||||
print("Memory error: ", e)
|
print("Memory error: ", e)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue