from machine import Pin
import time
ledRed = Pin(1,Pin.OUT)
ledYellow = Pin(5,Pin.OUT)
ledGreen = Pin(11,Pin.OUT)
btn1 = Pin(28,Pin.IN,Pin.PULL_DOWN)
btn2 = Pin(21,Pin.IN,Pin.PULL_DOWN)
btn3 = Pin(17,Pin.IN,Pin.PULL_DOWN)
duration1 = 4
duration2 = 2
duration3 = 4
while True:
try:
ledRed.value(1)
if btn1.value()==1:
duration1=int(input("Enter new time for red light.NB:seconds "))
elif btn2.value()==1:
duration2=int(input("Enter new time for yellow light.NB:seconds "))
elif btn3.value()==1:
duration3=int(input("Enter new time for green light.NB:seconds "))
time.sleep(duration1)
if btn1.value()==1:
duration1=int(input("Enter new time for red light.NB:seconds "))
elif btn2.value()==1:
duration2=int(input("Enter new time for yellow light.NB:seconds "))
elif btn3.value()==1:
duration3=int(input("Enter new time for green light.NB:seconds "))
ledRed.value(0)
if btn1.value()==1:
duration1=int(input("Enter new time for red light.NB:seconds "))
elif btn2.value()==1:
duration2=int(input("Enter new time for yellow light.NB:seconds "))
elif btn3.value()==1:
duration3=int(input("Enter new time for green light.NB:seconds "))
ledYellow.value(1)
if btn1.value()==1:
duration1=int(input("Enter new time for red light.NB:seconds "))
elif btn2.value()==1:
duration2=int(input("Enter new time for yellow light.NB:seconds "))
elif btn3.value()==1:
duration3=int(input("Enter new time for green light.NB:seconds "))
time.sleep(duration2)
if btn1.value()==1:
duration1=int(input("Enter new time for red light.NB:seconds "))
elif btn2.value()==1:
duration2=int(input("Enter new time for yellow light.NB:seconds "))
elif btn3.value()==1:
duration3=int(input("Enter new time for green light.NB:seconds "))
ledYellow.value(0)
if btn1.value()==1:
duration1=int(input("Enter new time for red light.NB:seconds "))
elif btn2.value()==1:
duration2=int(input("Enter new time for yellow light.NB:seconds "))
elif btn3.value()==1:
duration3=int(input("Enter new time for green light.NB:seconds "))
ledGreen.value(1)
if btn1.value()==1:
duration1=int(input("Enter new time for red light.NB:seconds "))
elif btn2.value()==1:
duration2=int(input("Enter new time for yellow light.NB:seconds "))
elif btn3.value()==1:
duration3=int(input("Enter new time for green light.NB:seconds "))
time.sleep(duration3)
if btn1.value()==1:
duration1=int(input("Enter new time for red light.NB:seconds "))
elif btn2.value()==1:
duration2=int(input("Enter new time for yellow light.NB:seconds "))
elif btn3.value()==1:
duration3=int(input("Enter new time for green light.NB:seconds "))
ledGreen.value(0)
if btn1.value()==1:
duration1=int(input("Enter new time for red light.NB:seconds "))
elif btn2.value()==1:
duration2=int(input("Enter new time for yellow light.NB:seconds "))
elif btn3.value()==1:
duration3=int(input("Enter new time for green light.NB:seconds "))
ledYellow.value(1)
if btn1.value()==1:
duration1=int(input("Enter new time for red light.NB:seconds "))
elif btn2.value()==1:
duration2=int(input("Enter new time for yellow light.NB:seconds "))
elif btn3.value()==1:
duration3=int(input("Enter new time for green light.NB:seconds "))
time.sleep(duration2)
if btn1.value()==1:
duration1=int(input("Enter new time for red light.NB:seconds "))
elif btn2.value()==1:
duration2=int(input("Enter new time for yellow light.NB:seconds "))
elif btn3.value()==1:
duration3=int(input("Enter new time for green light.NB:seconds "))
ledYellow.value(0)
if btn1.value()==1:
duration1=int(input("Enter new time for red light.NB:seconds "))
elif btn2.value()==1:
duration2=int(input("Enter new time for yellow light.NB:seconds "))
elif btn3.value()==1:
duration3=int(input("Enter new time for green light.NB:seconds "))
except ValueError:
print("Enter an integer value")
except Exception as e:
print(f"Error: {e}")
time.sleep(2)