You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
989 B
56 lines
989 B
|
|
#include "Arduino.h"
|
|
#include "SoftwareSerial.h"
|
|
#include "DFRobotDFPlayerMini.h"
|
|
|
|
SoftwareSerial mySoftwareSerial(10, 11);
|
|
DFRobotDFPlayerMini myDFPlayer;
|
|
|
|
#define LED 6
|
|
#define TRIG 4
|
|
#define SOUND 7
|
|
|
|
boolean trigger = LOW;
|
|
|
|
void setup() {
|
|
mySoftwareSerial.begin(9600);
|
|
Serial.begin(9600);
|
|
pinMode(TRIG, INPUT);
|
|
pinMode(SOUND, OUTPUT);
|
|
pinMode(LED, OUTPUT);
|
|
|
|
if (!myDFPlayer.begin(mySoftwareSerial)) {
|
|
Serial.println(F("Unable to begin:"));
|
|
Serial.println(F("1.Please recheck the connection!"));
|
|
Serial.println(F("2.Please insert the SD card!"));
|
|
while(true){
|
|
delay(0);
|
|
}
|
|
}
|
|
|
|
myDFPlayer.volume(20);
|
|
}
|
|
|
|
void loop() {
|
|
|
|
trigger = digitalRead(TRIG);
|
|
|
|
|
|
if(!trigger) {
|
|
|
|
myDFPlayer.play(1);
|
|
|
|
for(int i=0; i<25; i++) {
|
|
analogWrite(LED, i*10);
|
|
delay(random(5, 50-i));
|
|
analogWrite(LED, 0);
|
|
delay(random(5, 50-i));
|
|
}
|
|
|
|
analogWrite(LED, 255);
|
|
delay(5000);
|
|
|
|
} else {
|
|
digitalWrite(LED, LOW);
|
|
}
|
|
}
|