We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 7e7cb72 commit dabf4ecCopy full SHA for dabf4ec
examples/counter.py
@@ -0,0 +1,15 @@
1
+"""
2
+ counter.py
3
+ ~~~~~~~~~~
4
+ Creates a counter that increments on pressing button a.
5
+ Scrolls the current count on the led display.
6
7
+
8
+import microbit
9
+ctr = 0 # Initialize counter
10
+while True: # Loop forever
11
+ ctr = ctr + microbit.button_a.get_presses() # Count the amount of presses
12
+ microbit.button_a.reset_presses()
13
+ if ctr > 0: # Only execute if not zero
14
+ microbit.display.scroll(str(ctr)) # Display the counter
15
+ microbit.sleep(100) # Sleep for 100ms
0 commit comments