from machine import Pin
import time
# Define pin numbers
pinSwitch = 4
pinRelay = 5
# Initialize the pins
switch = Pin(pinSwitch, Pin.IN, Pin.PULL_UP)
relay = Pin(pinRelay, Pin.OUT)
while True:
# Read the state of the switch
switch_state = switch.value()
if switch_state == 0:
# Switch is pressed, activate the relay to toggle the LEDs
relay.value(1) # NO position: LED connected to this terminal will be ON
else:
# Switch is not pressed, deactivate the relay to switch the LEDs
relay.value(0) # NC position: LED connected to this terminal will be ON
# Add a small delay to debounce the switch
time.sleep(0.1)