from machine import Pin
from utime import sleep
red_pin = Pin(23, Pin.OUT)
green_pin = Pin(22, Pin.OUT)
blue_pin = Pin(18, Pin.OUT)
dp1_pin = Pin(32, Pin.IN, Pin.PULL_DOWN)
dp2_pin = Pin(33, Pin.IN, Pin.PULL_DOWN)
dp3_pin = Pin(25, Pin.IN, Pin.PULL_DOWN)
#####################################
###### MAIN ROUTINE
def main():
while True:
# Default: RGB OFF
sub_rgb_off()
# Read the state of the DIP switches
dp1_state = dp1_pin.value()
dp2_state = dp2_pin.value()
dp3_state = dp3_pin.value()
if dp1_state == 1 and dp2_state == 0 and dp3_state == 1:
sub_red_on()
elif dp1_state == 0 and dp2_state == 1 and dp3_state == 1:
sub_green_on()
elif dp1_state == 1 and dp2_state == 1 and dp3_state == 0:
sub_blue_on()
#elif dp1_state == 1 and dp2_state == 1 and dp3_state == 1:
#sub_white_on()
#####################################
###### SUBROUTINE FOR RGB LED
def sub_rgb_off():
red_pin.off()
green_pin.off()
blue_pin.off()
def sub_red_on():
red_pin.on()
def sub_green_on():
green_pin.on()
def sub_blue_on():
blue_pin.on()
#def sub_white_on():
#red_pin.on(); green_pin.on(); blue_pin.on()
#####################################
###### EXECUTE MAIN ROUTINE
if __name__ == '__main__':
main()Loading
esp32-devkit-c-v4
esp32-devkit-c-v4