import time
from machine import Pin, PWM
import utime, math
# pwm
pwm = PWM(Pin(2), freq=50, duty=0)
def Servo(servo, angle):
pwm.duty(int(((angle)/180 *2 + 0.5)/ 20 * 1023))
LED1 = Pin(19, Pin.OUT) #Red LED
LED2 = Pin(21, Pin.OUT) #Yellow LED
LED3 = Pin(22, Pin.OUT) #Green LED
#Red, yellow, green, repeat... :))
def rlight(sec):
LED1.value(1)
LED2.value(0)
LED3.value(0)
Servo(2,0)
time.sleep(sec) # seconds of red light (stop!)
def ylight(sec):
LED1.value(0)
LED2.value(1)
LED3.value(0)
time.sleep(sec) # seconds of red light (stop!)
def glight(sec):
LED1.value(0)
LED2.value(0)
LED3.value(1)
Servo(2,90)
time.sleep(sec) # seconds of red light (stop!)
rtime = int(input('input red light lasts seconds:'))
gtime = int(input('input green light lasts seconds:'))
while 1:
rlight(rtime)
glight(gtime-2)
ylight(2)