import machine
from machine import Pin, SoftI2C
from oled import I2C
import time
i2c = SoftI2C(scl=Pin(22), sda=Pin(21))
oled = I2C(128, 64, i2c)
# Buttons (use safe pins)
left = Pin(18, Pin.IN, Pin.PULL_UP)
right = Pin(19, Pin.IN, Pin.PULL_UP)
counter = 0
while True:
# Button pressed = 0 (because PULL_UP)
print(left.value(), right.value())
if left.value() == 0:
counter -= 1
time.sleep(0.2) # debounce
if right.value() == 0:
counter += 1
time.sleep(0.2) # debounce
# Display
oled.fill(0)
oled.text("Counter:", 0, 0)
oled.text(str(counter), 0, 2)
oled.show()Loading
esp32-devkit-c-v4
esp32-devkit-c-v4
Loading
ssd1306
ssd1306