print("Hello, ESP32!")
from machine import Pin
from utime import sleep
# Pin Configurations
led1_pin = Pin(2, Pin.OUT) # LED1
led2_pin = Pin(15, Pin.OUT) # LED2
dp1_pin = Pin(4, Pin.IN, Pin.PULL_DOWN) # DIP Switch 1 (Input with pull-down resistor)
dp2_pin = Pin(5, Pin.IN, Pin.PULL_DOWN) # DIP Switch 2 (Input with pull-down resistor)
# Subroutines for LED control
def sub_led1_on():
led1_pin.value(1)
def sub_led1_off():
led1_pin.value(0)
def sub_led2_on():
led2_pin.value(1)
def sub_led2_off():
led2_pin.value(0)
# Main routine
def main():
while True:
# Read DIP switch states
dp1_state = dp1_pin.value()
dp2_state = dp2_pin.value()
# Default state: Both LEDs OFF
if dp1_state == 0 and dp2_state == 0:
sub_led1_off()
sub_led2_off()
# Condition 1: DP1 pushed, DP2 released
elif dp1_state == 1 and dp2_state == 0:
sub_led1_on()
sub_led2_off()
# Condition 2: DP1 released, DP2 pushed
elif dp1_state == 0 and dp2_state == 1:
sub_led1_off()
sub_led2_on()
# Condition 3: Both DP1 and DP2 pushed
elif dp1_state == 1 and dp2_state == 1:
sub_led1_on()
sub_led2_on()
# Short delay to stabilize readings
sleep(0.1)
# Run the program
main()