From 482513c0244bc50d7b4abc8f6383edfad0dfa426 Mon Sep 17 00:00:00 2001 From: Mikayla Dobson Date: Mon, 7 Aug 2023 09:30:18 -0500 Subject: [PATCH] new color functions, readme --- README.md | 4 ++++ main.py | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..65f3237 --- /dev/null +++ b/README.md @@ -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. diff --git a/main.py b/main.py index d5c64a9..1d67d98 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ from machine import Pin, PWM +from random import choice from time import sleep U16_MAX = 65535 @@ -32,7 +33,6 @@ class RGB: return self.r, self.g, self.b - class StripLights: def __init__(self): self.B = Color(10) @@ -83,6 +83,15 @@ class StripLights: self.set_color(color) 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 = { 'PURPLE': RGB(255, 0, 255), 'RED': RGB(255, 0, 0), @@ -90,11 +99,13 @@ COLORS = { 'BLUE': RGB(0, 0, 255) } +COLORS_U16 = [color.to_u16() for color in COLORS.values()] + def main(): lights = StripLights() while True: - lights.color_cycle([color.to_u16() for color in COLORS.values()]) + lights.color_random(COLORS_U16) # while True: # lights.breathe(0.01)