import machine
import utime
led_blue = machine.Pin(13, machine.Pin.OUT)
led_cyan = machine.Pin(9, machine.Pin.OUT)
led_white = machine.Pin(5, machine.Pin.OUT)
led_yellow = machine.Pin(1, machine.Pin.OUT)
button_blue = machine.Pin(16, machine.Pin.IN, machine.Pin.PULL_UP)
button_cyan = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_UP)
button_white = machine.Pin(27, machine.Pin.IN, machine.Pin.PULL_UP)
button_yellow = machine.Pin(28, machine.Pin.IN, machine.Pin.PULL_UP)
blue_duration = 8
cyan_duration = 6
white_duration = 4
yellow_duration = 2
def update_duration(led, button):
global blue_duration, cyan_duration, white_duration, yellow_duration
while button.value() == 0:
new_duration = input("Enter new duration for " + led + " light (in seconds): ")
try:
new_duration = int(new_duration)
if new_duration > 0:
if led == "blue":
blue_duration = new_duration
elif led == "cyan":
cyan_duration = new_duration
elif led == "white":
white_duration = new_duration
elif led == "yellow":
yellow_duration == new_duration
print(led + " light duration updated to", new_duration, "seconds.")
break
else:
print("Invalid input. Duration must be a positive number.")
except ValueError:
print("Invalid input. Please enter a number.")
while True:
# Blue light
led_blue.on()
update_duration("blue", button_blue)
utime.sleep(blue_duration)
led_blue.off()
# Cyan light
led_cyan.on()
update_duration("cyan", button_cyan)
utime.sleep(cyan_duration)
led_cyan.off()
# White light
led_white.on()
update_duration("white", button_white)
utime.sleep(white_duration)
led_white.off()
# Yellow light
led_yellow.on()
update_duration("yellow", button_yellow)
utime.sleep(yellow_duration)
led_yellow.off()
# #As a computer engineering student, you're tasked with developing a home security program using a Rasberry PI Pico to simulate a lighting system for a home. The system should involve four leds, representing lights positioned around the compound of the home. Your program should allow the lights to be controlled via an input mechanism of your choice(I want you to use push button(s))
# The system should include the following functionalities
# 1. Turn On: All the lights should turn on simultaneously when a specific command is given
# 2. Blink in Sequence: The lights should blink in sequence(one after the other in a loop) on another command
# 3. Turn Off: All the lights should turn off when the appropriate command is entered
# Additionally the program must handle invalid inputs gracefully, providing appropriate ffedback without crashing. Implement this system in Micropython and design the circuit in Wokwi, ensuring proper GPIO configurations and a clear layout
# Instructions
# 1. Python controlledwrite a python code using Micropython for the Pi Pico