Skip to content

Commit 7e7cb72

Browse files
committed
Add simple hardware test script and README.
1 parent 7e7751e commit 7e7cb72

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

tests/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Tests
2+
=====
3+
4+
This directory contains script[s] that can be used to confirm various features
5+
of the micro:bit are working. They are as follows:
6+
7+
* `exercise.py` - a general exercise of various aspects of the hardware. Not exhaustive and requires the user to press buttons A or B to move forward in the tests. Completes with a smile.
8+
* ??? - TBC
9+

tests/exercise.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Exercises the micro:bit - NOT EXHAUSTIVE!
2+
from microbit import *
3+
import music
4+
import random
5+
6+
7+
# Press A to start.
8+
while True:
9+
if button_a.was_pressed():
10+
break
11+
else:
12+
display.show(Image.ARROW_W)
13+
sleep(200)
14+
display.clear()
15+
sleep(200)
16+
17+
18+
# Asyncronously play a jolly little tune (connect speaker to pin0 and GND)
19+
music.play(music.NYAN, wait=False)
20+
21+
22+
# Grab all the built in images.
23+
images = [getattr(Image, img) for img in dir(Image)
24+
if type(getattr(Image, img)) == Image]
25+
# ... and cycle through them on the display.
26+
pause = 1000
27+
for img in images:
28+
display.show(img)
29+
sleep(pause)
30+
pause -= 50
31+
if pause < 100:
32+
pause = 100
33+
display.clear()
34+
35+
36+
# Aural testing of the accelerometer.
37+
display.scroll("Accelerometer")
38+
display.show("X")
39+
while not button_a.is_pressed():
40+
music.pitch(abs(accelerometer.get_x()), 20)
41+
sleep(500)
42+
display.show("Y")
43+
while not button_a.is_pressed():
44+
music.pitch(abs(accelerometer.get_y()), 20)
45+
sleep(500)
46+
display.show("Z")
47+
while not button_a.is_pressed():
48+
music.pitch(abs(accelerometer.get_z()), 20)
49+
50+
51+
# Aural testing of the compass.
52+
display.scroll("Compass")
53+
compass.calibrate()
54+
while not button_b.is_pressed():
55+
music.pitch(abs(compass.heading()), 20)
56+
57+
58+
# Pixel brightness.
59+
display.scroll("Display")
60+
dots = [ [0]*5, [0]*5, [0]*5, [0]*5, [0]*5 ]
61+
while not button_a.is_pressed():
62+
dots[random.randrange(5)][random.randrange(5)] = 9
63+
for i in range(5):
64+
for j in range(5):
65+
display.set_pixel(i, j, dots[i][j])
66+
dots[i][j] = max(dots[i][j] - 1, 0)
67+
sleep(50)
68+
69+
70+
# ??? Add further tests here...
71+
72+
73+
# Finished!
74+
display.scroll("Finished!")
75+
display.show(Image.HAPPY)

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