'''
from machine import Pin, Timer
from time import sleep
led_green = Pin(22,Pin.OUT)
led_blue = Pin(21,Pin.OUT)
led_red = Pin(23,Pin.OUT)
button_pin19 = Pin(34, Pin.IN)
def handler_2(tim2):
global switch
if switch ==0:
tim2.deinit()
elif switch == 1:
led_green.value(not led_green.value())
elif switch ==2:
led_blue.value(not led_blue.value())
elif switch ==3:
led_red.value(not led_red.value())
else:
tim2.deinit()
switch = 0
tim2=Timer(2)
switch=0
while True:
if button_pin19.value()==1:
sleep(0.1)
if button_pin19.value()==1:
sleep(0.1)
switch = switch+1
if switch ==1:
led_blue.value(0)
led_red.value(0)
tim2.init(period=1500, mode=Timer.PERIODIC, callback=handler_2)
sleep(0.1)
elif switch == 2:
led_green.value(0)
led_blue.value(0)
tim2.init(period=1000, mode=Timer.PERIODIC, callback=handler_2)
sleep(0.1)
elif switch == 3:
led_blue.value(0)
led_red.value(0)
tim2.init(period=500, mode=Timer.PERIODIC, callback=handler_2)
sleep(0.1)
else:
switch=0
tim2.deinit()
led_blue.value(0)
led_red.value(0)
led_green.value(0)
switch_status = "The value of switch is {} and button is {}"
print(switch_status .format(switch,button_pin19.value()),end = "\r")
'''
from machine import Pin, Timer
from time import sleep
#DECLERING LED VIRIABLES
led_23 = Pin(23,Pin.OUT) #RED LED
led_22 = Pin(22,Pin.OUT) #GREEN LED
led_21 = Pin(21,Pin.OUT) #BLUE LED
#SINGLE PUSH BUTTON DECLERATIOON
button_pin20 = Pin(20, Pin.IN, Pin.PULL_UP)
#DEFINING handlers FUNCTIONS FOR ALL LED’S
def handler_23(tim23):
led_23.value(not led_23.value())
def handler_22(tim22):
led_22.value(not led_22.value())
def handler_21(tim21):
led_21.value(not led_21.value())
#DECLARING time VARIABLES
tim23 =Timer(23)
tim22 =Timer(22)
tim21 =Timer(21)
# The variable "temp"is used to check which "if" condition should be executed
# everytime the pushbutton is pressed switch=0
while True:
if button_pin23.value()==0:
sleep(0.1)
if button_pin23.value()==0:
switch = switch+1
if switch ==1:
tim23.init(period=500, mode=Timer.PERIODIC, callback=handler_23)
elif switch == 2:
tim23.deinit()
switch=0
sleep(0.1)
led.value(0)
switch_status = "The value of switch here on Red is {}"
print(switch_status .format(switch),end = "\r")
if button_pin22.value()==0:
sleep(0.1)
if button_pin22.value()==0: switch = switch+1
if switch ==1:
tim22.init(period=1000, mode=Timer.PERIODIC, callback=handler_22)
elif switch == 2: tim22.deinit() switch=0 sleep(0.1) led.value(0)
switch_status = "The value of switch here on Red is {}"
print(switch_status .format(switch),end = "\r")
while True:
if button_pin21.value()==0:
sleep(0.1)
if button_pin21.value()==0: switch = switch+1
if switch ==1:
tim21.init(period=1500, mode=Timer.PERIODIC, callback=handler_21)
elif switch == 2: tim21.deinit() switch=0 sleep(0.1) led.value(0)
switch_status = "The value of switch here on Red is {}"
print(switch_status .format(switch),end = "\r")