modelButtons

Button A counts its presses (scrolled on the display), button B resets the counter - the presses are driven from the diagram (BooleanPulse)

Extends from Modelica.Icons.Example (Icon for runnable examples).

Information

Expected result: the script scrolls A=+1 B=0 at start, then 1, 2, 3... each time pressA fires (presses at 1.5 s, 2.5 s, 3.5 s, 4.5 s - button_a.was_pressed() never misses one). The pin P5 falls to 0 V during each press and returns to 3 V through its 10 kOhm pull-up.

The presses come from the diagram (buttonA input of the board), like a finger on the real board; the program itself runs unchanged on a physical micro:bit.

Components

TypeNameDefaultDescription
MicroPythonMCU.MicroBit_v2mbProgram: Resources/Scripts/MCU/microbit_buttons.py
Modelica.Electrical.Analog.Basic.Groundground
Modelica.Blocks.Sources.BooleanPulsepressAButton A pressed during 100 ms, every second
Modelica.Blocks.Sources.BooleanConstantbtnBbutton B idle