File: counter.py

package info (click to toggle)
firmware-microbit-micropython 1.0.1-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid
  • size: 25,448 kB
  • sloc: ansic: 83,496; cpp: 27,664; python: 2,475; asm: 274; makefile: 245; javascript: 41; sh: 25
file content (14 lines) | stat: -rw-r--r-- 587 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
"""
    counter.py
    ~~~~~~~~~~
    Creates a counter that increments on pressing button a.
    Scrolls the current count on the led display.
"""

import microbit
ctr = 0                                         # Initialize counter
while True:                                     # Loop forever
    ctr = ctr + microbit.button_a.get_presses() # Count the amount of presses 
    if ctr > 0:                                 # Only execute if not zero
        microbit.display.scroll(str(ctr))       # Display the counter
    microbit.sleep(100)                         # Sleep for 100ms