6
6
License: MIT. See license file for more information but you can
7
7
basically do whatever you want with this code.
8
8
9
- The MY1690 has a large number of features. This example presents the user
10
- with a serial menu to control the various aspects of the IC.
11
-
12
9
Feel like supporting our work? Buy a board from SparkFun!
13
10
MY1690X Serial MP3 Player Shield: https://www.sparkfun.com/sparkfun-serial-mp3-player-shield-my1690x.html
14
11
MY1690X Audio Player Breakout: https://www.sparkfun.com/sparkfun-audio-player-breakout-my1690x-16s.html
@@ -39,7 +36,7 @@ SparkFunMY1690 myMP3;
39
36
void setup ()
40
37
{
41
38
Serial.begin (115200 );
42
- Serial.println (F (" MY1690 MP3 Example" ));
39
+ Serial.println (F (" MY1690 MP3 Example 1 - Play File " ));
43
40
44
41
serialMP3.begin (9600 ); // The MY1690 expects serial communication at 9600bps
45
42
@@ -77,152 +74,17 @@ void setup()
77
74
else if (playStatus == 0 )
78
75
Serial.println (F (" (stopped)" ));
79
76
80
- myMP3.setVolume (5 ); // 30 is loudest. 5 is comfortable with headphones. 0 is mute.
77
+ myMP3.setVolume (15 ); // 30 is loudest. 15 is comfortable with headphones. 0 is mute.
81
78
82
79
Serial.print (F (" Volume: " ));
83
80
Serial.println (myMP3.getVolume ());
84
81
85
82
myMP3.setPlayModeNoLoop ();
86
83
87
- mainMenu ( );
84
+ Serial. print ( F ( " Example Complete. " ) );
88
85
}
89
86
90
87
void loop ()
91
88
{
92
- if (Serial.available ())
93
- {
94
- byte incoming = Serial.read ();
95
- if (incoming == ' s' )
96
- {
97
- if (myMP3.stopPlaying () == true )
98
- Serial.println (" Stop success" );
99
- else
100
- Serial.println (" Stop command failed" );
101
- }
102
- else if (incoming == ' x' )
103
- {
104
- if (myMP3.reset () == true )
105
- Serial.println (" Reset success" );
106
- else
107
- Serial.println (" Reset command failed" );
108
- }
109
- else if (incoming == ' a' )
110
- {
111
- myMP3.volumeUp ();
112
- Serial.print (" Volume: " );
113
- Serial.println (myMP3.getVolume ());
114
- }
115
- else if (incoming == ' z' )
116
- {
117
- myMP3.volumeDown ();
118
- Serial.print (" Volume: " );
119
- Serial.println (myMP3.getVolume ());
120
- }
121
- else if (incoming == ' f' )
122
- {
123
- myMP3.fastForward ();
124
- }
125
- else if (incoming == ' r' )
126
- {
127
- myMP3.rewind ();
128
- }
129
- else if (incoming == ' p' )
130
- {
131
- myMP3.playPause ();
132
- }
133
- else if (incoming == ' e' )
134
- {
135
- int currentEQ = myMP3.getEQ ();
136
- currentEQ++; // Go to next EQ. Device automatically wraps.
137
-
138
- myMP3.setEQ (currentEQ);
139
-
140
- currentEQ = myMP3.getEQ ();
141
- Serial.print (F (" Current EQ: " ));
142
- Serial.println (currentEQ);
143
- }
144
- else if (incoming == ' m' )
145
- {
146
- int currentMode = myMP3.getPlayMode ();
147
- currentMode++; // Go to next mode.
148
-
149
- if (currentMode > 4 )
150
- currentMode = 0 ;
151
-
152
- myMP3.setPlayMode (currentMode);
153
-
154
- currentMode = myMP3.getPlayMode ();
155
- Serial.print (F (" Current Mode: " ));
156
- Serial.println (currentMode);
157
- }
158
- else if (incoming == ' <' )
159
- {
160
- myMP3.playPrevious ();
161
- }
162
- else if (incoming == ' >' )
163
- {
164
- myMP3.playNext ();
165
- }
166
- else if (incoming == ' #' )
167
- {
168
- delay (20 );
169
- while (Serial.available ()) Serial.read ();
170
-
171
- Serial.println (F (" Track number to play: " ));
172
- while (Serial.available () == 0 ) delay (1 );
173
- int value = Serial.parseInt ();
174
-
175
- // Note: Track must be named 0001.mp3 to myMP3.playTrackNumber(1)
176
- myMP3.playTrackNumber (value);
177
- }
178
- else if (incoming == ' c' )
179
- {
180
- Serial.print (F (" Current track: " ));
181
- Serial.println (myMP3.getTrackNumber ());
182
- }
183
- else if (incoming == ' t' )
184
- {
185
- Serial.print (F (" Current track elapsed time (s): " ));
186
- Serial.println (myMP3.getTrackElapsedTime ());
187
- }
188
- else if (incoming == ' T' )
189
- {
190
- Serial.print (F (" Current track length (s): " ));
191
- Serial.println (myMP3.getTrackTotalTime ());
192
- }
193
- else if (incoming == ' \r ' || incoming == ' \n ' )
194
- {
195
- // Ignore these
196
- }
197
- else
198
- {
199
- Serial.print (F (" Unknown command: " ));
200
- Serial.write (incoming);
201
- Serial.println ();
202
- mainMenu ();
203
- }
204
- }
205
- }
206
89
207
- void mainMenu ()
208
- {
209
- Serial.println ();
210
- Serial.println (F (" SparkFun MY1690 Menu:" ));
211
-
212
- Serial.println (F (" s) Stop play" ));
213
- Serial.println (F (" x) Reset IC" ));
214
- Serial.println (F (" a) Volume up" ));
215
- Serial.println (F (" z) Volume down" ));
216
- Serial.println (F (" f) Fast forward" ));
217
- Serial.println (F (" r) Reverse" ));
218
- Serial.println (F (" p) Play/Pause toggle" ));
219
- Serial.println (F (" e) Set EQ" ));
220
- Serial.println (F (" m) Set play mode" ));
221
- Serial.println (F (" <) Play previous" ));
222
- Serial.println (F (" >) Play next" ));
223
- Serial.println (F (" #) Play track number" ));
224
- Serial.println (F (" c) Current track number" ));
225
- Serial.println (F (" t) Track elapsed time" ));
226
- Serial.println (F (" T) Track total time" ));
227
- Serial.println (F (" Enter command:" ));
228
- }
90
+ }
0 commit comments