# FUNCIONAMIENTO: SWITCH LEFT ----> prende LED, SWITCH RIGHT ---> Apaga LED
# A- PROGRAMACIÓN SECUENCIAL (ESTRUICTURADA)
from machine import Pin
from time import sleep
switch = Pin(7,Pin.IN,Pin.PULL_UP)
led = Pin(26,Pin.OUT)
while True:
if switch.value()==0: # SWITCH LEFT
led.value(1)
else: # SWITCH RIGHT
led.value(0)
sleep(.1) # Anti bounce
#********************************************
# B- PROGRAMACIÓN MEDIANTE FUNCIONES
"""
from machine import Pin
from time import sleep
def encender_led():
led.value(1)
def apagar_led():
led.value(0)
switch = Pin(7, Pin.IN, Pin.PULL_UP)
led = Pin(26, Pin.OUT)
while True:
if switch.value() == 0:
encender_led()
else:
apagar_led()
sleep(0.1)
"""
#********************************************
#C- PROGRAMACIÓN MEDIANTE POO
"""
from machine import Pin
from time import sleep
class LedControl:
def __init__(self, pin_sw, pin_led):
self.sw = Pin(pin_sw, Pin.IN, Pin.PULL_UP)
self.led = Pin(pin_led, Pin.OUT)
def encender_led(self):
self.led.value(1)
def apagar_led(self):
self.led.value(0)
def control(self):
while True:
if self.sw.value() == 0:
self.encender_led()
else:
self.apagar_led()
sleep(0.1)
# Configuración de pines
pin_sw = 7
pin_led = 26
# Crear instancia de la clase LedControl y controlar el LED
led_control = LedControl(pin_sw, pin_led)
led_control.control()
"""
#*************************************************************