MantisIDE

Read a button

Guide by MantisIDE Team · Fri Nov 27 2026 · 0 points · 0 comments

Print when a push button (pin to ground) is pressed.

A starter program from the MantisIDE Full IDE (Tools › Examples). Press Open in Full IDE to run it on your board, change it, and save it as your own.

# Print when a push button (pin to ground) is pressed.
from machine import Pin
import time

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

last = 1
while True:
    now = button.value()
    if now != last:
        print("pressed" if now == 0 else "released")
        last = now
    time.sleep_ms(20)  # simple debounce
Loading post…

Dialog