Skip to content

Commit 8971eff

Browse files
First push of code and docs
1 parent 80b8918 commit 8971eff

File tree

5 files changed

+428
-8
lines changed

5 files changed

+428
-8
lines changed

README.rst

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,24 @@ Or the following command to update an existing version:
8989
Usage Example
9090
=============
9191

92-
.. todo:: Add a quick, simple example. It and other examples should live in the
93-
examples folder and be included in docs/examples.rst.
92+
.. code-block:: python
93+
94+
import board
95+
import busio
96+
from mindwidgets_df1201s import DF1201S
97+
98+
uart = busio.UART(tx=board.GP16, rx=board.GP17, baudrate=115200)
99+
100+
df_player = DF1201S(uart)
101+
df_player.volume = 0.2
102+
df_player.play_mode = DF1201S.PLAYMODE_PLAY_ONCE
103+
104+
if not df_player.play_next():
105+
print("No sound files to play!")
106+
107+
while True:
108+
pass
109+
94110
95111
Documentation
96112
=============

docs/examples.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
Simple test
22
------------
33

4-
Ensure your device works with this simple test.
4+
Ensure your device works with this simple test. When working, will play the first
5+
sound stored on the DFPlayer Pro.
56

67
.. literalinclude:: ../examples/df1201s_simpletest.py
78
:caption: examples/df1201s_simpletest.py
89
:linenos:
10+
11+
More Features
12+
--------------
13+
14+
Explore more features of the DFPlayer Pro, including volume adjustment, play modes,
15+
and play status.
16+
17+
.. literalInclude:: ../examples/df1201s_morefeatures.py
18+
:caption: examples/df1201s_morefeatures.py
19+
:linenos:

examples/df1201s_morefeatures.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 Aaron Silinskas for Mindwidgets
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import board
6+
import time
7+
import busio
8+
from mindwidgets_df1201s import DF1201S
9+
10+
uart = busio.UART(tx=board.GP16, rx=board.GP17, baudrate=115200)
11+
12+
df_player = DF1201S(uart)
13+
14+
print("Disabling start-up prompt (persists after power off)")
15+
df_player.disable_prompt()
16+
17+
print("Volume:", df_player.volume)
18+
df_player.volume = 0.2
19+
print("New Volume:", df_player.volume)
20+
df_player.increase_volume(0.05)
21+
print("Increased Volume:", df_player.volume)
22+
df_player.decrease_volume(0.1)
23+
print("Decreased Volume:", df_player.volume)
24+
df_player.play_mode = DF1201S.PLAYMODE_REPEAT_ONE_SONG
25+
print("Mode:", df_player.play_mode)
26+
27+
print("File Count:", df_player.total_files)
28+
29+
df_player.enable_led()
30+
print("Play song")
31+
32+
if not df_player.play_next():
33+
print("No sound files to play!")
34+
35+
print("Current file number:", df_player.file_number)
36+
print("Current file name: ", df_player.file_name)
37+
print("Length of the current file in seconds:", df_player.total_time)
38+
39+
while df_player.playing:
40+
time.sleep(0.5)
41+
42+
print("Done playing")
43+
44+
df_player.disable_led()
45+
46+
while True:
47+
pass

examples/df1201s_simpletest.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries
21
# SPDX-FileCopyrightText: Copyright (c) 2022 Aaron Silinskas for Mindwidgets
32
#
4-
# SPDX-License-Identifier: Unlicense
3+
# SPDX-License-Identifier: MIT
4+
5+
import board
6+
import busio
7+
from mindwidgets_df1201s import DF1201S
8+
9+
uart = busio.UART(tx=board.GP16, rx=board.GP17, baudrate=115200)
10+
11+
df_player = DF1201S(uart)
12+
df_player.volume = 0.2
13+
df_player.play_mode = DF1201S.PLAYMODE_PLAY_ONCE
14+
15+
if not df_player.play_next():
16+
print("No sound files to play!")
17+
18+
while True:
19+
pass

0 commit comments

Comments
 (0)