new color functions, readme
This commit is contained in:
4
README.md
Normal file
4
README.md
Normal 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
15
main.py
@@ -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)
|
||||||
|
|||||||
Reference in New Issue
Block a user