MP3 Player. (This is nice.)
This commit is contained in:
@@ -12,3 +12,4 @@
|
|||||||
platform = atmelavr
|
platform = atmelavr
|
||||||
board = uno
|
board = uno
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
lib_deps = https://github.com/DFRobot/DFRobotDFPlayerMini
|
||||||
|
|||||||
+32
-21
@@ -1,31 +1,42 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#define LED 13
|
#include <SoftwareSerial.h>
|
||||||
|
#include "DFRobotDFPlayerMini.h"
|
||||||
|
|
||||||
void displayMicros();
|
int music_num;
|
||||||
void displayMillis();
|
SoftwareSerial mySoftwareSerial(10, 11); // #1
|
||||||
|
DFRobotDFPlayerMini myDFPlayer; // #2
|
||||||
|
|
||||||
// Setup Section
|
// Setup Section
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
mySoftwareSerial.begin(9600);
|
||||||
pinMode(LED, OUTPUT);
|
Serial.begin(115200);
|
||||||
attachInterrupt(0, displayMicros, RISING); // #1
|
myDFPlayer.begin(mySoftwareSerial); // #3
|
||||||
attachInterrupt(1, displayMillis, RISING);
|
myDFPlayer.volume(20);
|
||||||
}
|
|
||||||
|
|
||||||
void displayMicros() {
|
|
||||||
Serial.write("micros() = ");
|
|
||||||
Serial.println(micros());
|
|
||||||
}
|
|
||||||
|
|
||||||
void displayMillis() {
|
|
||||||
Serial.write("millis() = ");
|
|
||||||
Serial.println(millis());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop Section
|
// Loop Section
|
||||||
void loop() {
|
void loop() {
|
||||||
digitalWrite(LED, HIGH);
|
if (Serial.available() > 0) {
|
||||||
delay(500);
|
music_num = Serial.readString().toInt(); // #4
|
||||||
digitalWrite(LED, LOW);
|
if (music_num < 5 && music_num > 0) {
|
||||||
delay(500);
|
switch (music_num) {
|
||||||
|
case 1:
|
||||||
|
Serial.println("1");
|
||||||
|
myDFPlayer.play(1);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
Serial.println("2");
|
||||||
|
myDFPlayer.play(2);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
Serial.println("3");
|
||||||
|
myDFPlayer.play(3);
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
Serial.println("4");
|
||||||
|
myDFPlayer.play(4);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user