Skip to content

Commit

Permalink
Added R2-D2 mailbox project, basic code that plays sounds in a loop
Browse files Browse the repository at this point in the history
  • Loading branch information
jameselsey committed Dec 15, 2024
1 parent a490aef commit 73a5e8c
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
5 changes: 5 additions & 0 deletions arduino_projects/r2d2_mailbox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
R2-D2 Mailbox
=============

This project is a mailbox made from an old gas bottle to look like R2-D2 from Star Wars.
I've also added some electronics to it so it plays sounds when a person goes near it, to amuse the mailman and local dog walkers!
112 changes: 112 additions & 0 deletions arduino_projects/r2d2_mailbox/r2d2_mailbox/r2d2_mailbox.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#include "Arduino.h"
#include "DFRobotDFPlayerMini.h"

#define DFPSerial Serial1

#define DFP_VOLUME 3 // from 0 to 30
#define DFP_RX_PIN 16
#define DFP_TX_PIN 17

DFRobotDFPlayerMini myDFPlayer;
void printDetail(uint8_t type, int value);

void setup()
{
Serial.begin(115200);

DFPSerial.begin(9600, SERIAL_8N1, DFP_RX_PIN, DFP_TX_PIN);


Serial.println();
Serial.println(F("DFRobot DFPlayer Mini Demo"));
Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)"));

if (!myDFPlayer.begin(DFPSerial, /*isACK = */true, /*doReset = */true)) {
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);
}
}
Serial.println(F("DFPlayer Mini online."));

myDFPlayer.volume(DFP_VOLUME);
myDFPlayer.play(1);
}

void loop()
{
static unsigned long timer = millis();

if (millis() - timer > 5000) {
timer = millis();
myDFPlayer.next(); //Play next mp3 every x seconds.
}

if (myDFPlayer.available()) {
printDetail(myDFPlayer.readType(), myDFPlayer.read()); //Print the detail message from DFPlayer to handle different errors and states.
}
}

void printDetail(uint8_t type, int value){
switch (type) {
case TimeOut:
Serial.println(F("Time Out!"));
break;
case WrongStack:
Serial.println(F("Stack Wrong!"));
break;
case DFPlayerCardInserted:
Serial.println(F("Card Inserted!"));
break;
case DFPlayerCardRemoved:
Serial.println(F("Card Removed!"));
break;
case DFPlayerCardOnline:
Serial.println(F("Card Online!"));
break;
case DFPlayerUSBInserted:
Serial.println("USB Inserted!");
break;
case DFPlayerUSBRemoved:
Serial.println("USB Removed!");
break;
case DFPlayerPlayFinished:
Serial.print(F("Number:"));
Serial.print(value);
Serial.println(F(" Play Finished!"));
break;
case DFPlayerError:
Serial.print(F("DFPlayerError:"));
switch (value) {
case Busy:
Serial.println(F("Card not found"));
break;
case Sleeping:
Serial.println(F("Sleeping"));
break;
case SerialWrongStack:
Serial.println(F("Get Wrong Stack"));
break;
case CheckSumNotMatch:
Serial.println(F("Check Sum Not Match"));
break;
case FileIndexOut:
Serial.println(F("File Index Out of Bound"));
break;
case FileMismatch:
Serial.println(F("Cannot Find File"));
break;
case Advertise:
Serial.println(F("In Advertise"));
break;
default:
break;
}
break;
default:
break;
}

}

0 comments on commit 73a5e8c

Please sign in to comment.