breadboard
docs

Example project · Start here

Black Pill F411CE · MicroPython LED and button

Boot the Breadboard TinyUSB build of MicroPython over native USB CDC. Code pulses the onboard LED, prints the active-low button, then leaves the LED lit. When Serial prompts, press and release KEY to read 0 then 1; the script waits for you. First boot formats the filesystem and can take about two minutes of wall time.

The Black Pill F411CE · MicroPython LED and button circuit as rendered by the simulator

What's on the bench

  • WeAct Black Pill F411CE

The code

This MicroPython script runs on the emulated board every boot; edit it in Code.

from machine import Pin
from time import sleep_ms
led = Pin('C13', Pin.OUT)
button = Pin('A0', Pin.IN, Pin.PULL_UP)
for state in (1, 0, 1):
    led.value(1 - state)
    print('BLACKPILL LED', state, 'BUTTON', button.value())
    sleep_ms(250)
print('Press KEY now')
while button.value():
    sleep_ms(20)
print('BUTTON_PRESSED', button.value())
while not button.value():
    sleep_ms(20)
print('BUTTON_RELEASED', button.value())

Related projects