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/
Sunday, 29 January 2023
4Buttons to control RGB led using Raspberry Pi Pico
from picozero import Button, RGBLED
from time import sleep
rgb = RGBLED(red = 1, green = 2, blue = 3)
button = Button(18)
option = 0 # store the current option
def choice(): # call the next function and update the option
global option
if option == 0:
rgb.color = (255, 0, 0)
elif option == 1:
rgb.color = (0, 255, 0)
elif option == 2:
rgb.color = (0, 0, 255)
elif option == 3:
rgb.off()
# move to the next option
if option == 3:
option = 0
else:
option = option + 1
button.when_pressed = choice # Call the choice function when the button is pressed
#https://projects.raspberrypi.org/en/projects/
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment