66 License: MIT. See license file for more information but you can
77 basically do whatever you want with this code.
88
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-
129 Feel like supporting our work? Buy a board from SparkFun!
1310 MY1690X Serial MP3 Player Shield: https://www.sparkfun.com/sparkfun-serial-mp3-player-shield-my1690x.html
1411 MY1690X Audio Player Breakout: https://www.sparkfun.com/sparkfun-audio-player-breakout-my1690x-16s.html
@@ -39,7 +36,7 @@ SparkFunMY1690 myMP3;
3936void setup ()
4037{
4138 Serial.begin (115200 );
42- Serial.println (F (" MY1690 MP3 Example" ));
39+ Serial.println (F (" MY1690 MP3 Example 1 - Play File " ));
4340
4441 serialMP3.begin (9600 ); // The MY1690 expects serial communication at 9600bps
4542
@@ -77,152 +74,17 @@ void setup()
7774 else if (playStatus == 0 )
7875 Serial.println (F (" (stopped)" ));
7976
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.
8178
8279 Serial.print (F (" Volume: " ));
8380 Serial.println (myMP3.getVolume ());
8481
8582 myMP3.setPlayModeNoLoop ();
8683
87- mainMenu ( );
84+ Serial. print ( F ( " Example Complete. " ) );
8885}
8986
9087void loop ()
9188{
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- }
20689
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