File: test_music.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 (46 lines) | stat: -rw-r--r-- 1,030 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

from microbit import display, Image, pin0, pin1, pin2, pin8
import music

PINS = pin0, pin1, pin2, pin8
FREQS = 400, 500, 600, 700, 800, 900

def test_rapid_pin_switch():
    for i in range(20):
        for pin in PINS:
            music.play(music.NYAN, pin, wait=False)

def test_rapid_pitch_switch():
    for i in range(20):
        for freq in FREQS:
            music.pitch(freq, wait=False)

def test_repeated_stop():
    for i in range(20):
        music.stop()

def test_repeated_reset():
    for i in range(20):
        music.reset()

def test_repeated_set_tempo():
    for i in range(20):
        music.set_tempo(ticks=i%4+1, bpm=i+100)

def test_all_pins_free():
    for pin in PINS:
        pin.read_digital()

display.clear()
try:
    test_rapid_pin_switch()
    test_rapid_pitch_switch()
    test_repeated_stop()
    test_repeated_reset()
    test_repeated_set_tempo()
    test_all_pins_free()
    print("File test: PASS")
    display.show(Image.HAPPY)
except Exception as ae:
    display.show(Image.SAD)
    raise