import time
time.sleep(0.1) # Wait for USB to become ready
print("Hello, Pi Pico!")
from Lights import *
from Button import *
from Log import *
from LightStrip import *
from Buzzer import *
from Displays import *
class RainbowLight(LightStrip):
"""
A subclass of Lightstrip that shows colors of the rainbow when turned on
"""
def __init__(self, pin=2, name='Neopixel', numleds=16, brightness=0.5):
""" Call superclass's init method to initialize the light strip """
super().__init__(pin, name, numleds, brightness)
def on(self):
"""
Overriding the superclass method On by setting different colors to different pixels
"""
# Identify the separte light bulbs (pixels)
colors = [PURPLE, INDIGO, BLUE, GREEN, YELLOW, ORANGE, RED]
# Assign a color value to each of the pixels - put these colors on the pixels
for colorindex in range(0,7):
self.setPixel(colorindex , colors[colorindex], show=False)
# Show the colors
self.show()
class Lab1:
"""
Lab 1 class - encapsulates all the hardware lab 1 uses
"""
def __init__(self):
"""
Create instances of all the classes in variables
"""
self.redled = Light(pin=20, name="Red LED")
self.bluebutton = Button(15, "Blue", handler = self)
self.yellowbutton = Button(14, "Yellow", handler = self)
self.lightstrip = RainbowLight(pin=2, name="Light strip", numleds=8, brightness=0.5)
self.buzzer = PassiveBuzzer(pin=17, name="Buzzer")
self.display = LCDDisplay(sda=0, scl=1)
def buttonPressed(self, name):
"""
ButtonPressed handler
"""
if name == 'Blue':
self.redled.on()
self.buzzer.play(200)
self.display.showText("LED On")
elif name == 'Yellow':
self.lightstrip.on()
self.buzzer.play(1000)
self.display.showText("LightStrip On")
def buttonReleased(self, name):
self.redled.off()
self.lightstrip.off()
self.buzzer.stop()
self.display.clear()
def run(self):
while True:
time.sleep(1)
mylab = Lab1()
mylab.run()