from machine import Pin
import time
# Define pins
led = Pin(27, Pin.OUT)
button1 = Pin(10, Pin.IN)
button2 = Pin(11, Pin.IN)
buzzer = Pin(26, Pin.OUT)
RED_PIN = Pin(21, Pin.OUT)
GREEN_PIN = Pin(20, Pin.OUT)
BLUE_PIN = Pin(19, Pin.OUT)
# Initialize the LED status as False
led_status = False
# Function to set RGB color
def set_color(red, green, blue):
RED_PIN.value(red)
GREEN_PIN.value(green)
BLUE_PIN.value(blue)
# Main loop
while True:
# Button 1 logic for LED
if button1.value() == 1: # If button1 is pressed
led.value(1) # Turn on LED
led_status = True
else:
led.value(0) # Turn off LED
led_status = False
# Button 2 logic for buzzer
if button2.value() == 1: # If button2 is pressed
buzzer.value(1) # Turn on buzzer
else:
buzzer.value(0) # Turn off buzzer
# Cycle through RGB colors
set_color(1, 0, 0) # Red
time.sleep(1)
set_color(0, 1, 0) # Green
time.sleep(1)
set_color(0, 0, 1) # Blue
time.sleep(1)