🛠 Réagir aux boutons A, B et au pad tactile du logo

micro:bit V2 (BBC micro:bit v2) · debutant · Schéma : IMG-microbit-v2-debutant-2-microbit-v2-boutons-ab.svg — micro:bit V2 avec doigts appuyant sur les boutons A et B et doigt touchant le logo tactile, flèches de liaison vers la matrice LED

Objectives

Use the two physical buttons A (internal pin P0.14) and B (P0.23) as well as the capacitive touch logo (FACE_TOUCH, P1.04) specific to the V2, to control the display of the 5×5 matrix.

Materials

Complete code

from microbit import *

while True:
    if button_a.was_pressed:
        display.show(Image.HAPPY)
        sleep(600)
    elif button_b.was_pressed:
        display.show(Image.SAD)
        sleep(600)
    elif pin_logo.is_touched:
        display.show(Image.HEART)
        sleep(600)
    else:
        display.show(Image.SILLY)

was_pressed returns true only once per press (internal flag), which avoids unwanted repetitions. pin_logo.is_touched reads the capacitive pad of the large logo — a new feature of the V2; the rings P0, P1, P2 are also touch-sensitive.

Expected verification

Button A: happy smiley. Button B: sad face. Finger on the logo: heart. At rest: silly face. Each press changes the display immediately, without visible bouncing.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials