Autformat the rest
This commit is contained in:
parent
1350a433a7
commit
aecc9347c9
15 changed files with 164 additions and 115 deletions
|
|
@ -7,6 +7,7 @@
|
|||
# License: MIT License (https://opensource.org/licenses/MIT)
|
||||
|
||||
import time
|
||||
|
||||
import board
|
||||
import neopixel
|
||||
|
||||
|
|
@ -19,18 +20,54 @@ symbol_gap = dot_length # Duration of gap between dot or dash
|
|||
character_gap = (dot_length * 3.0) # Duration of gap between characters
|
||||
flash_color = (255, 0, 0) # Color of the morse display.
|
||||
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',
|
||||
'...'), ('T', '-'), ('U', '..-'), ('V', '...-'), ('W', '.--'), ('X', '-..-'), ('Y', '-.--'), ('Z', '--..'), ('0', '-----'), ('1', '.----'), ('2', '..---'), ('3', '...--'), ('4', '....-'), ('5', '.....'), ('6', '-....'), ('7', '--...'), ('8', '---..'), ('9', '----.')]
|
||||
morse = [
|
||||
('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.
|
||||
|
||||
|
||||
class MorseFlasher:
|
||||
|
||||
def __init__(self, color=(255, 255, 255)):
|
||||
# set the color adjusted for brightness
|
||||
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):
|
||||
if on:
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
import board
|
||||
import time
|
||||
import pulseio
|
||||
from digitalio import DigitalInOut, Direction, Pull
|
||||
from analogio import AnalogIn
|
||||
|
||||
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)
|
||||
servo = adafruit_motor.servo.Servo(pwm)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import board
|
||||
import neopixel
|
||||
import time
|
||||
|
||||
try:
|
||||
import urandom as random # for v1.0 API support
|
||||
except ImportError:
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
import time
|
||||
|
||||
import analogio
|
||||
import board
|
||||
import digitalio
|
||||
import analogio
|
||||
import neopixel
|
||||
import time
|
||||
|
||||
try:
|
||||
import urandom as random # for v1.0 API support
|
||||
except:
|
||||
|
|
@ -58,7 +60,7 @@ while True: # Loop forever...
|
|||
last_vibration = t # Save last trigger time
|
||||
|
||||
# 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
|
||||
if frame_len > max_frame_len:
|
||||
frame_len = min_frame_len
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import time
|
||||
from analogio import AnalogIn
|
||||
|
||||
import adafruit_character_lcd
|
||||
import adafruit_fancyled.adafruit_fancyled as fancy
|
||||
import board
|
||||
import digitalio
|
||||
import adafruit_character_lcd
|
||||
import neopixel
|
||||
from analogio import AnalogIn
|
||||
|
||||
lcd_rs = digitalio.DigitalInOut(board.D5)
|
||||
lcd_en = digitalio.DigitalInOut(board.D6)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import time
|
||||
import math
|
||||
from analogio import AnalogIn
|
||||
import time
|
||||
|
||||
import adafruit_character_lcd
|
||||
import board
|
||||
import digitalio
|
||||
import adafruit_character_lcd
|
||||
import neopixel
|
||||
from analogio import AnalogIn
|
||||
|
||||
lcd_rs = digitalio.DigitalInOut(board.D5)
|
||||
lcd_en = digitalio.DigitalInOut(board.D6)
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
from analogio import AnalogIn
|
||||
import board
|
||||
import time
|
||||
|
||||
import board
|
||||
import neopixel
|
||||
from analogio import AnalogIn
|
||||
|
||||
pot = AnalogIn(board.A1) # what pin the pot is on
|
||||
pixpin = board.D0 # what pin the LEDs are on
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import time
|
||||
|
||||
import board
|
||||
import neopixel
|
||||
import time
|
||||
|
||||
pixpin = board.D1
|
||||
numpix = 7
|
||||
|
|
@ -24,17 +25,17 @@ def wheel(pos):
|
|||
if (pos < 0) or (pos > 255):
|
||||
return (0, 0, 0)
|
||||
if (pos < 85):
|
||||
return (int(pos * 3), int(255 - (pos*3)), 0)
|
||||
return (int(pos * 3), int(255 - (pos * 3)), 0)
|
||||
elif (pos < 170):
|
||||
pos -= 85
|
||||
return (int(255 - pos*3), 0, int(pos*3))
|
||||
return (int(255 - pos * 3), 0, int(pos * 3))
|
||||
else:
|
||||
pos -= 170
|
||||
return (0, int(pos*3), int(255 - pos*3))
|
||||
return (0, int(pos * 3), int(255 - pos * 3))
|
||||
|
||||
|
||||
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)):
|
||||
idx = int((r * 255 / len(pixels)) + j)
|
||||
pixels[r] = wheel(idx & 255)
|
||||
|
|
@ -45,14 +46,14 @@ def rainbow_cycle(wait):
|
|||
def rainbow(wait):
|
||||
for j in range(255):
|
||||
for i in range(len(pixels)):
|
||||
idx = int(i+j)
|
||||
idx = int(i + j)
|
||||
pixels[i] = wheel(idx & 255)
|
||||
pixels.write()
|
||||
time.sleep(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)):
|
||||
idx = int((r * 255 / len(pixels)) + j)
|
||||
pixels[r] = wheel(idx & 255)
|
||||
|
|
@ -61,7 +62,7 @@ def rainbow_cycle_slow(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)):
|
||||
idx = int((r * 255 / len(pixels)) + j)
|
||||
pixels[r] = wheel(idx & 255)
|
||||
|
|
@ -87,7 +88,7 @@ while True:
|
|||
|
||||
if ((t - prevtime) > 8): # Every 8 seconds...
|
||||
mode += 1 # Next mode
|
||||
if(mode > 2): # End of modes?
|
||||
if (mode > 2): # End of modes?
|
||||
mode = 0 # Start modes over
|
||||
|
||||
if (rgb_idx > 2): # reset R-->G-->B rotation
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
from digitalio import DigitalInOut, Direction
|
||||
import time
|
||||
|
||||
import board
|
||||
import neopixel
|
||||
import time
|
||||
from digitalio import DigitalInOut, Direction
|
||||
|
||||
pixpin = board.D1
|
||||
numpix = 5
|
||||
|
|
@ -24,13 +25,13 @@ def wheel(pos):
|
|||
if (pos < 0) or (pos > 255):
|
||||
return (0, 0, 0)
|
||||
if (pos < 85):
|
||||
return (int(pos * 3), int(255 - (pos*3)), 0)
|
||||
return (int(pos * 3), int(255 - (pos * 3)), 0)
|
||||
elif (pos < 170):
|
||||
pos -= 85
|
||||
return (int(255 - pos*3), 0, int(pos*3))
|
||||
return (int(255 - pos * 3), 0, int(pos * 3))
|
||||
else:
|
||||
pos -= 170
|
||||
return (0, int(pos*3), int(255 - pos*3))
|
||||
return (0, int(pos * 3), int(255 - pos * 3))
|
||||
|
||||
|
||||
def rainbow_cycle(wait):
|
||||
|
|
@ -44,12 +45,11 @@ def rainbow_cycle(wait):
|
|||
def rainbow(wait):
|
||||
for j in range(255):
|
||||
for i in range(len(strip)):
|
||||
idx = int(i+j)
|
||||
idx = int(i + j)
|
||||
strip[i] = wheel(idx & 255)
|
||||
|
||||
|
||||
while True:
|
||||
|
||||
colorWipe((255, 0, 0), .1) # red and delay
|
||||
colorWipe((0, 255, 0), .1) # green and delay
|
||||
colorWipe((0, 0, 255), .1) # blue and delay
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import time
|
||||
|
||||
import board
|
||||
import neopixel
|
||||
import time
|
||||
|
||||
try:
|
||||
import urandom as random
|
||||
except ImportError:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import board
|
||||
import neopixel
|
||||
import time
|
||||
|
||||
try:
|
||||
import urandom as random
|
||||
except ImportError:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import time
|
||||
|
||||
import board
|
||||
import neopixel
|
||||
import time
|
||||
|
||||
try:
|
||||
import urandom as random # for v1.0 API support
|
||||
except ImportError:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import time
|
||||
|
||||
import board
|
||||
import neopixel
|
||||
import time
|
||||
|
||||
try:
|
||||
import urandom as random
|
||||
except ImportError:
|
||||
|
|
@ -17,7 +19,6 @@ colors = [
|
|||
|
||||
|
||||
def flash_random(wait, howmany):
|
||||
|
||||
for k in range(howmany):
|
||||
|
||||
c = random.randint(0, len(colors) - 1) # Choose random color index
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from digitalio import DigitalInOut, Direction
|
||||
import board
|
||||
import busio
|
||||
import time
|
||||
from digitalio import DigitalInOut, Direction
|
||||
|
||||
try:
|
||||
import struct
|
||||
except ImportError:
|
||||
|
|
@ -66,4 +66,4 @@ while True:
|
|||
print("---------------------------------------")
|
||||
|
||||
buffer = buffer[32:]
|
||||
#print("Buffer ", buffer)
|
||||
# print("Buffer ", buffer)
|
||||
|
|
|
|||
Loading…
Reference in a new issue