Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Module specification and pins reference is [here](https://wiki.dfrobot.com/DFPla
Playback control:
```python
play(track_id) # track_id, 'next' or 'prev'
play(track_id, folder) # track_id in folder (both integers)
pause()
resume()
loop_track(track_id)
Expand Down Expand Up @@ -62,11 +63,12 @@ music.fadeout(2000)

music.play(2)
music.loop()
music.play(3, 2) # Plays track 3 in folder 2
sleep(20)

music.module_sleep()
```

## License

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details
12 changes: 8 additions & 4 deletions dfplayermini.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def __init__(self, pin_TX, pin_RX):
self._max_volume = 15
self._fadeout_speed = 0

def cmd(self, command, parameter=0x00):
def cmd(self, command, parameter=0x00, highparameter=0x00):
query = bytes([0x7e, 0xFF, 0x06, command,
0x00, 0x00, parameter, 0xEF])
0x00, highparameter, parameter, 0xEF])
self.uart.write(query)

def _fade_out_process(self, timer):
Expand All @@ -34,8 +34,12 @@ def _fade_out_process(self, timer):

# playback

def play(self, track_id=False):
if not track_id:
def play(self, track_id=False, folder=False):
if folder and track_id:
self.cmd(0x0F, track_id, highparameter=folder)
# NB cmd 0X0F requires folder and track_id params.
# 'High' byte and 'Low' byte in the DFRobot C code.
elif not track_id:
self.resume()
elif track_id == 'next':
self.cmd(0x01)
Expand Down