This blog is a record of what I do, what I think and what I read. If you are interested to know about my professional experience, you can refer to the other blog of mine. http://admi2camac.blogspot.com/
Friday, 27 January 2023
2RGB led running on Raspberry Pi Pico
from picozero import RGBLED
from time import sleep
rgb = RGBLED(red = 1, green = 2, blue = 3)
rgb.blink() # red for 1 second, green for 1 second, blue for 1 second
print("Blinking with all colors") # Runs immediately
sleep(3)
rgb.off()
# blink purple 2 seconds, off 0.5 seconds
rgb.blink(on_times=(2, 0.5), colors=((255, 0, 255), (0, 0, 0)), wait=True, n=3)
print("Finished blinking purple") # Runs after 3 repeats
sleep(3)
rgb.off()
# blink red 1 second, green 0.5 seconds, blue 0.25 seconds
rgb.blink((1, 0.5, 0.25), colors=((255, 0, 0), (0, 255, 0), (0, 0, 255)), wait=True, n=2)
print("Finished blinking different color different duration") # Runs after 2 blink repeats
sleep(3)
rgb.off()
for x in range(1, 4, 1):
rgb.color = (255, 0, 0)
sleep(0.5)
rgb.color = (0, 255, 0)
sleep(0.5)
rgb.color = (0, 0, 255)
sleep(0.5)
print("ON and OFF the 3 colors")
rgb.off()
rgb.pulse() # pulse red for 1 second, green for 1 second, blue for 1 second
print("Pulsing") # Runs immediately
sleep(3)
rgb.off()
# 2 second to fade from purple to off, 0.5 seconds to change from off to purple
rgb.pulse(fade_times=(2, 0.5), colors=((255, 0, 255), (0, 0, 0)), wait=True, n=3)
print("Finished pulsing") # Runs after 3 pulses
sleep(3)
rgb.off()
rgb.cycle() # Gradually colour cycle through colours between red and green, green and blue then blue and red
print("Cycle") # Runs immediately
sleep(3)
rgb.off()
# Colour cycle slower in the opposite direction
rgb.cycle(fade_times=3, colors=((0, 0, 255), (0, 255, 0), (255, 0, 0)), wait=True, n=2)
print("Cycle slowly 2 times")
sleep(3)
rgb.off()
#https://projects.raspberrypi.org/en/projects/introduction-to-the-pico/8
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment