Skip to content

Commit cf309e9

Browse files
Mark Shannondpgeorge
authored andcommitted
Add toy compass example.
1 parent 5bf9325 commit cf309e9

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

examples/compass.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from microbit import *
2+
3+
needles = (Image.CLOCK12, Image.CLOCK1, Image.CLOCK2, Image.CLOCK3,
4+
Image.CLOCK4, Image.CLOCK5, Image.CLOCK6, Image.CLOCK7,
5+
Image.CLOCK8, Image.CLOCK9, Image.CLOCK10, Image.CLOCK11)
6+
7+
# You need to spin the microbit about a few times to help calibrate the compass
8+
9+
# Scroll a message to encourage user to help calibrate the compass
10+
# "Spin" "Me!" reads better than "Spin Me!" due to lack of kerning
11+
display.scroll("Spin")
12+
display.scroll("Me!")
13+
14+
# Start calibrating
15+
compass.calibrate()
16+
17+
# Spin needle until calibrated.
18+
while compass.is_calibrating():
19+
for i in range(12):
20+
display.print(needles[i])
21+
sleep(80)
22+
display.clear()
23+
24+
# Try to keep needle pointed in (roughly) the same direction
25+
while True:
26+
sleep(500)
27+
needle = ((15 - compass.heading()) // 30) % 12
28+
display.print(needles[needle])

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy