from machine import Pin
from utime import sleep
# RGB LED Output Pins (Adjust if you wired R, G, B to different pins)
red_pin = Pin(2, Pin.OUT)
green_pin = Pin(4, Pin.OUT)
blue_pin = Pin(16, Pin.OUT)
# DIP Switch Input Pins (Matches your Wokwi wiring: DP1=19, DP2=18, DP3=5)
dp1_pin = Pin(18, Pin.IN)
dp2_pin = Pin(19, Pin.IN)
dp3_pin = Pin(5, Pin.IN)
# Subroutines for RGB LED states
def sub_rgb_off():
red_pin.off()
green_pin.off()
blue_pin.off()
def sub_rgb_red():
red_pin.on()
green_pin.off()
blue_pin.off()
def sub_rgb_green():
red_pin.off()
green_pin.on()
blue_pin.off()
def sub_rgb_blue():
red_pin.off()
green_pin.off()
blue_pin.on()
def main():
while True:
dp1 = dp1_pin.value()
dp2 = dp2_pin.value()
dp3 = dp3_pin.value()
if dp1 == 0 and dp2 == 0 and dp3 == 0:
sub_rgb_off()
elif dp1 == 1 and dp2 == 0 and dp3 == 1:
sub_rgb_red()
elif dp1 == 0 and dp2 == 1 and dp3 == 1:
sub_rgb_green()
elif dp1 == 1 and dp2 == 1 and dp3 == 0:
sub_rgb_blue()
else:
sub_rgb_off()
sleep(0.1)
if __name__ == '__main__':
main()Loading
esp32-devkit-c-v4
esp32-devkit-c-v4