print("Hello, ESP32!")
from machine import Pin
from utime import sleep
# Pin Configurations
red_pin = Pin(4, Pin.OUT) # RED_LED
green_pin = Pin(0, Pin.OUT) # GREEN_LED
blue_pin = Pin(2, Pin.OUT) # BLUE_LED
dp1_pin = Pin(14, Pin.IN, Pin.PULL_DOWN) # DIP Switch 1
dp2_pin = Pin(27, Pin.IN, Pin.PULL_DOWN) # DIP Switch 2
dp3_pin = Pin(26, Pin.IN, Pin.PULL_DOWN) # DIP Switch 3
# Subroutines for RGB LED control
def led_off():
red_pin.value(0)
green_pin.value(0)
blue_pin.value(0)
def led_red():
red_pin.value(0)
green_pin.value(1)
blue_pin.value(1)
def led_green():
red_pin.value(1)
green_pin.value(0)
blue_pin.value(1)
def led_blue():
red_pin.value(1)
green_pin.value(1)
blue_pin.value(0)
# Main routine
def main():
while True:
# Read DIP switch states
dp1_state = dp1_pin.value()
dp2_state = dp2_pin.value()
dp3_state = dp3_pin.value()
# Default state: RGB LED OFF
if dp1_state == 0 and dp2_state == 0 and dp3_state == 0:
led_off()
# Condition 1: DP1 pushed, DP2 released, DP3 pushed
elif dp1_state == 1 and dp2_state == 0 and dp3_state == 1:
led_red()
# Condition 2: DP1 released, DP2 pushed, DP3 pushed
elif dp1_state == 0 and dp2_state == 1 and dp3_state == 1:
led_green()
# Condition 3: DP1 and DP2 pushed, DP3 released
elif dp1_state == 1 and dp2_state == 1 and dp3_state == 0:
led_blue()
# Short delay to stabilize readings
sleep(0.1)
# Run the program
main()