print("Hello, ESP32!")
#####################################
###### IMPORT LIBRARIES
from machine import Pin
from time import sleep
#####################################
###### PIN CONFIGURATIONS
# Configure the LED and Pushbutton pins
pin_led = Pin(21, Pin.OUT)
pin_pb = Pin(2, Pin.IN)
#####################################
###### SUBROUTINE FOR INTERRUPT
# This function is triggered on pushbutton press
def interrupt_pb(pin):
print('Interrupt by:', pin)
pin_led.on()
sleep(1) # LED stays ON for 5 seconds
pin_led.off()
sleep(1)
# Interrupt trigger on falling edge (button push)
pin_pb.irq(trigger=Pin.IRQ_FALLING, handler=interrupt_pb)
#####################################
###### MAIN ROUTINE
def main():
while True:
# LED stays off unless interrupted
pin_led.off()
sleep(10)
#####################################
###### EXECUTE MAIN ROUTINE
if __name__ == '__main__':
main()