print("Hello, ESP32!")
##################################################
###### IMPORT LIBRARIES
from machine import Pin
from utime import sleep
##################################################
###### PIN CONFIGURATIONS
# Configure the pin as output
# Replace the w & x with your GPIO Pin W & X number here
led1_pin = Pin(12, Pin.OUT)
led2_pin = Pin(13, Pin.OUT)
# Configure the pin as input
# Replace the y & z with your GPIO Pin Y & Z number here
dp1_pin = Pin(25, Pin.IN)
dp2_pin = Pin(26, Pin.IN)
##################################################
###### MAIN ROUTINE
def main():
while True:
# DP1 & DP2 released, LED1 & LED2 always OFF
sub_led1_off()
sub_led2_off()
# Read the state of the push button
dp1_state = dp1_pin.value()
dp2_state = dp2_pin.value()
# If DP1 is pushed AND DP2 is released
if dp1_state == 1 and dp2_state == 0:
# then LED1 ON
sub_led1_on()
# then LED2 OFF
sub_led2_off()
# If DP1 is released AND DP2 is pushed
elif dp1_state == 0 and dp2_state == 1:
# then LED1 OFF
sub_led1_off()
# then LED2 ON
sub_led2_on()
# If DP1 & DP2 are pushed
elif dp1_state == 1 and dp2_state == 1:
# then LED1 ON
sub_led1_on()
# then LED2 ON
sub_led2_on()
# continue loop
##################################################
###### SUBROUTINE FOR LED
def sub_led1_on():
led1_pin.on()
def sub_led1_off():
led1_pin.off()
def sub_led2_on():
led2_pin.on()
def sub_led2_off():
led2_pin.off()
##################################################
###### EXECUTE MAIN ROUTINE
if __name__ == '__main__':
main()Loading
esp32-devkit-c-v4
esp32-devkit-c-v4