-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathpicodfplayer_example.py
53 lines (39 loc) · 1.21 KB
/
picodfplayer_example.py
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
47
48
49
50
51
52
53
#In order ror this example-code to work, make sure you have a
#card with at least one folder, containing at least two mp3:s.
#The folders should be named 01, 02 etc and files should be named
#001.mp3, 002.mp3 etc.
from utime import sleep_ms, sleep
from picodfplayer import DFPlayer
#Constants. Change these if DFPlayer is connected to other pins.
UART_INSTANCE=0
TX_PIN = 16
RX_PIN=17
BUSY_PIN=6
#Create player instance
player=DFPlayer(UART_INSTANCE, TX_PIN, RX_PIN, BUSY_PIN)
#Check if player is busy.
print('Playing?', player.queryBusy())
#Play the first song (001.mp3) from the first folder (01)
print('Playing track 001.mp3 in folder 01')
player.playTrack(1,1)
#Wait 5 seconds...
sleep(5)
#Pause
print('Pausing')
player.pause()
#Wait 2 seconds...
sleep(2)
#Resume
print('Resuming play')
player.resume()
#Wait 5 seconds
sleep(5)
#Next Track
print('Skipping to next track')
player.nextTrack()
#Wait 5 seconds
sleep(5)
#Pause by directly sending the pause (0x0E) command to the command line and printing the output.
print('Pausing by sending the pause command manually, and printing the output')
print(str(player.sendcmd(0x0E, 0x00, 0x00)))
print('You can try me out by sending commands in the console, such as player.resume()')