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/

No comments: