Digital Input Pullup example script (phyduino.py) Reads a pushbutton on D2 using the pin's pull-up resistor, so no other parts are needed, prints its state and lights the on-board LED while it is pressed.
- Wiring
- A pushbutton between D2 and GND. The pull-up holds D2 at 1 while the button is open, so the logic is inverted: pressed reads 0.
import time
import phyduino as mcu
button = mcu.pin("D2", "in", pull="up")
while True:
state = button.value()
print(state)
mcu.led.value(not state)
time.sleep(0.1)