new color functions, readme

This commit is contained in:
2023-08-07 09:30:18 -05:00
parent d9627dfd1f
commit 482513c024
2 changed files with 17 additions and 2 deletions

4
README.md Normal file
View File

@@ -0,0 +1,4 @@
# IOT with Micropython and Raspberry Pi Pico W
Starting a new project here towards building out a toolkit for developing some custom IOT tools, as well as associated web hosting
technologies to host and interact with these tools.

15
main.py
View File

@@ -1,4 +1,5 @@
from machine import Pin, PWM from machine import Pin, PWM
from random import choice
from time import sleep from time import sleep
U16_MAX = 65535 U16_MAX = 65535
@@ -32,7 +33,6 @@ class RGB:
return self.r, self.g, self.b return self.r, self.g, self.b
class StripLights: class StripLights:
def __init__(self): def __init__(self):
self.B = Color(10) self.B = Color(10)
@@ -83,6 +83,15 @@ class StripLights:
self.set_color(color) self.set_color(color)
sleep(sleep_interval) sleep(sleep_interval)
def color_random(self, color_list, sleep_interval=1, logging=False):
color = choice(color_list)
self.set_color(color)
if logging:
print(color)
sleep(sleep_interval)
COLORS = { COLORS = {
'PURPLE': RGB(255, 0, 255), 'PURPLE': RGB(255, 0, 255),
'RED': RGB(255, 0, 0), 'RED': RGB(255, 0, 0),
@@ -90,11 +99,13 @@ COLORS = {
'BLUE': RGB(0, 0, 255) 'BLUE': RGB(0, 0, 255)
} }
COLORS_U16 = [color.to_u16() for color in COLORS.values()]
def main(): def main():
lights = StripLights() lights = StripLights()
while True: while True:
lights.color_cycle([color.to_u16() for color in COLORS.values()]) lights.color_random(COLORS_U16)
# while True: # while True:
# lights.breathe(0.01) # lights.breathe(0.01)