Materials

Digital Input

button.py

'''
button.py
'''

from machine import Pin
from time import sleep_msx

button = Pin(12, Pin.IN, Pin.PULL_UP)

while True:
    if not button.value():
        print('Button pressed!')
    sleep_ms(20)

Hookup Pattern

button

  1. Connect 1 button pin to ESP32 Pin 12
  2. Connect another button pin to ESP32 GND

Digital Input / Digital Output

button_led.py

'''
buttonLed.py
'''

from machine import Pin
from time import sleep_ms

button = Pin(12, Pin.IN, Pin.PULL_UP)
led = Pin(27, Pin.OUT)

while True:
    if not button.value():
        led.value(1)
    else:
        led.value(0)
    sleep_ms(20)

Hookup Pattern

button_led

  1. Connect 1 button pin to ESP32 Pin 12
  2. Connect ESP32 GND to a blue bus on the side of your breadboard
  3. Connect another button pin to the same blue bus on the side of your breadboard
  4. From pin 27, connect the following in series: a Resistor to an LED to GND (blue bus)

Previous Post Next Post