forked from umarsear/ESP8266-Connected-MP3-Player
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmp3.py
82 lines (62 loc) · 1.4 KB
/
mp3.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from time import sleep
from machine import UART
uart=UART(0,9600)
import yx5300 as cmd
# set initial volume to mid point
volume_level=15
initialized=False
# do necessary initialization
# Currently only the volume is set
def initialize():
global initialized
global volume_level
if not initialized:
set_volume(volume_level)
initialized=True
sleep(0.5)
def next():
initialize()
uart.write(cmd.play_next())
def previous():
initialize()
uart.write(cmd.play_previous())
def hibernate():
uart.write(cmd.sleep_module())
def wakeup():
uart.write(cmd.wake_module())
def reset():
global initialized
initialized=False
uart.write(cmd.reset_module())
def play_track(track_id):
initialize()
uart.write(cmd.play_track(track_id))
def play():
initialize()
play_track(1);
def pause():
uart.write(cmd.pause())
def resume():
uart.write(cmd.resume())
def stop():
uart.write(cmd.stop())
def set_volume(level):
global volume_level
volume_level=level
uart.write(cmd.set_volume(level))
def volume_up(step_count=1):
global volume_level
volume_level=volume_level+step_count
set_volume(volume_level)
def volume_down(step_count=1):
global volume_level
volume_level=volume_level-step_count
set_volume(volume_level)
def mute():
uart.write(cmd.set_volume(0))
def unmute():
global volume_level
uart.write(cmd.set_volume(volume_level))
def get_volume():
global volume_level
return volume_level