1
0
mirror of https://github.com/xfjx/TonUINO.git synced 2025-08-23 23:13:24 +02:00

Initial commit

This commit is contained in:
Thorsten Voß
2018-07-28 18:39:50 +02:00
parent babf2d39f3
commit 5e3116cfd8
107 changed files with 336 additions and 0 deletions

296
JukeBox.ino Normal file
View File

@@ -0,0 +1,296 @@
#include <SPI.h>
#include <MFRC522.h>
#include <SoftwareSerial.h>
#include <DFMiniMp3.h>
#include <EEPROM.h>
//DFPlayer Mini
SoftwareSerial mySoftwareSerial(2, 3); // RX, TX
uint16_t numTracksInFolder;
uint16_t track;
struct StoredCard {
byte id[4];
int folder;
byte mode;
byte reserved1; // Um in Zukunft noch weitere Optionen
byte reserved2; // konfigurieren zu können
byte reserved3; // reservieren wir einfach mal ein paar Integer
};
StoredCard myCard;
static void nextTrack();
bool foundCard = false;
// implement a notification class,
// its member methods will get called
//
class Mp3Notify
{
public:
static void OnError(uint16_t errorCode)
{
// see DfMp3_Error for code meaning
Serial.println();
Serial.print("Com Error ");
Serial.println(errorCode);
}
static void OnPlayFinished(uint16_t track)
{
Serial.print("Track beendet");
Serial.println(track);
delay(100);
nextTrack();
}
static void OnCardOnline(uint16_t code)
{
Serial.println(F("SD Karte online "));
}
static void OnCardInserted(uint16_t code)
{
Serial.println(F("SD Karte bereit "));
}
static void OnCardRemoved(uint16_t code)
{
Serial.println(F("SD Karte entfernt "));
}
};
static DFMiniMp3<SoftwareSerial, Mp3Notify> mp3(mySoftwareSerial);
// Leider kann das Modul keine Queue abspielen.
static void nextTrack() {
if (foundCard == false)
// Wenn eine neue Karte angelernt wird soll das Ende eines Tracks nicht verarbeitet werden
return;
if (myCard.mode == 1)
{
Serial.println(F("Hörspielmodus ist aktiv -> Strom sparen"));
mp3.sleep();
}
if (myCard.mode == 2)
{
Serial.println(F("Albummodus ist aktiv -> nächster Track"));
if (track != numTracksInFolder) {
track = track + 1;
mp3.playFolderTrack(myCard.folder, track);
} else
mp3.sleep();
}
if (myCard.mode == 3)
{
Serial.println(F("Party Modus ist aktiv -> zufälligen Track spielen"));
track = random(1, numTracksInFolder + 1);
mp3.playFolderTrack(myCard.folder, track);
}
}
// MFRC522
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522
uint8_t successRead;
byte readCard[4]; // Stores scanned ID read from RFID Module
const int buttonPause = A0;
const int buttonUp = A1;
const int buttonDown = A2;
uint8_t numberOfCards = 0;
void setup() {
Serial.begin(115200); // Es gibt ein paar Debug Ausgaben über die serielle Schnittstelle
randomSeed(analogRead(A0)); // Zufallsgenerator initialisieren
Serial.println(F("DIY NFC JUKEBOX"));
Serial.println(F("BY THORSTEN VOß"));
// Knöpfe mit PullUp
pinMode(buttonPause, INPUT_PULLUP);
pinMode(buttonUp, INPUT_PULLUP);
pinMode(buttonDown, INPUT_PULLUP);
// NFC Leser initialisieren
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522
mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader
// DFPlayer Mini initialisieren
mp3.begin();
mp3.reset();
mp3.setVolume(10);
// RESET --- ALLE DREI KNÖPFE BEIM STARTEN GEDRÜCKT HALTEN -> alle bekannten Karten werden gelöscht
if (digitalRead(buttonPause) == LOW && digitalRead(buttonUp) == LOW && digitalRead(buttonDown) == LOW) {
Serial.println(F("Reset -> EEPROM wird gelöscht"));
for (int i = 0 ; i < EEPROM.length() ; i++) {
EEPROM.write(i, 0);
}
}
// Anzahl bekannter Karten auslesen
numberOfCards = EEPROM.read(0);
}
void loop() {
do {
successRead = getID();
mp3.loop();
if (digitalRead(buttonPause) == LOW) {
Serial.println(F("Play/Pause"));
if (mp3.getStatus() == 513)
mp3.pause();
else
mp3.start();
delay(500);
}
if (digitalRead(buttonUp) == LOW) {
Serial.println(F("Volume Up"));
mp3.increaseVolume();
}
if (digitalRead(buttonDown) == LOW) {
Serial.println(F("Volume Down"));
mp3.decreaseVolume();
}
}
while (!successRead);
foundCard = false;
for (int x = 0; x < numberOfCards; x++) {
EEPROM.get(sizeof(StoredCard) * x + sizeof(int), myCard);
if (checkTwo(readCard, myCard.id))
{
foundCard = true;
numTracksInFolder = mp3.getFolderTrackCount(myCard.folder);
// Hörspielmodus: eine zufällige Datei aus dem Ordner
if (myCard.mode == 1) {
Serial.println(F("Hörspielmodus -> zufälligen Track wiedergeben"));
track = random(1, numTracksInFolder + 1);
Serial.println(track);
mp3.playFolderTrack(myCard.folder, track);
}
// Album Modus: kompletten Ordner spielen
if (myCard.mode == 2) {
Serial.println(F("Album Modus -> kompletten Ordner wiedergeben"));
track = 1;
mp3.playFolderTrack(myCard.folder, track);
}
// Party Modus: Ordner in zufälliger Reihenfolge
if (myCard.mode == 3) {
Serial.println(F("Party Modus -> Ordner in zufälliger Reihenfolge wiedergeben"));
track = random(1, numTracksInFolder + 1);
mp3.playFolderTrack(myCard.folder, track);
}
break;
}
}
// Neue Karte konfigurieren
if (foundCard == false) {
Serial.print(F("Neue Karte konfigurieren"));
for (int i = 0; i < 4; i++)
myCard.id[i] = readCard[i];
myCard.folder = 0;
myCard.mode = 0;
bool done = false;
mp3.playMp3FolderTrack(100);
do {
if (digitalRead(buttonPause) == LOW) {
done = true;
delay(1000);
}
if (digitalRead(buttonUp) == LOW) {
myCard.folder = min(myCard.folder + 1, 99);
//mp3.playMp3FolderTrack(myCard.folder);
mp3.playFolderTrack(myCard.folder, 1);
delay(1000);
}
if (digitalRead(buttonDown) == LOW) {
myCard.folder = max(myCard.folder - 1, 1);
//mp3.playMp3FolderTrack(myCard.folder);
mp3.playFolderTrack(myCard.folder, 1);
delay(1000);
}
}
while (done == false);
done = false;
mp3.playMp3FolderTrack(101);
do {
if (digitalRead(buttonPause) == LOW) {
done = true;
delay(1000);
}
if (digitalRead(buttonUp) == LOW) {
myCard.mode = min(myCard.mode + 1, 3);
mp3.playMp3FolderTrack(101 + myCard.mode);
delay(1000);
}
if (digitalRead(buttonDown) == LOW) {
myCard.mode = max(myCard.mode - 1, 1);
mp3.playMp3FolderTrack(101 + myCard.mode);
delay(1000);
}
}
while (done == false);
mp3.playMp3FolderTrack(110);
EEPROM.put(sizeof(StoredCard) * numberOfCards + sizeof(int), myCard);
numberOfCards = numberOfCards + 1;
EEPROM.put(0, numberOfCards);
}
}
///////////////////////////////////////// Get PICC's UID ///////////////////////////////////
uint8_t getID() {
// Getting ready for Reading PICCs
if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
return 0;
}
if ( ! mfrc522.PICC_ReadCardSerial()) { //Since a PICC placed get Serial and continue
return 0;
}
// There are Mifare PICCs which have 4 byte or 7 byte UID care if you use 7 byte PICC
// I think we should assume every PICC as they have 4 byte UID
// Until we support 7 byte PICCs
Serial.println(F("Scanned PICC's UID:"));
for ( uint8_t i = 0; i < 4; i++) { //
readCard[i] = mfrc522.uid.uidByte[i];
Serial.print(readCard[i], HEX);
}
Serial.println("");
mfrc522.PICC_HaltA(); // Stop reading
return 1;
}
///////////////////////////////////////// Check Bytes ///////////////////////////////////
boolean checkTwo ( byte a[], byte b[] ) {
boolean match = false; // initialize card match to false
if ( a[0] != 0 ) // Make sure there is something in the array first
match = true; // Assume they match at first
for ( uint8_t k = 0; k < 4; k++ ) { // Loop 4 times
if ( a[k] != b[k] ) // IF a != b then set match = false, one fails, all fail
match = false;
}
if ( match ) { // Check to see if if match is still true
return true; // Return true
}
else {
return false; // Return false
}
}

BIN
SD-Karte/mp3/0001.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0002.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0003.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0004.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0005.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0006.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0007.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0008.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0009.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0010.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0011.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0012.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0013.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0014.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0015.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0016.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0017.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0018.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0019.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0020.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0021.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0022.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0023.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0024.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0025.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0026.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0027.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0028.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0029.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0030.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0031.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0032.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0033.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0034.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0035.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0036.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0037.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0038.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0039.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0040.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0041.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0042.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0043.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0044.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0045.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0046.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0047.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0048.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0049.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0050.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0051.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0052.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0053.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0054.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0055.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0056.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0057.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0058.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0059.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0060.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0061.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0062.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0063.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0064.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0065.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0066.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0067.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0068.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0069.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0070.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0071.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0072.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0073.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0074.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0075.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0076.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0077.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0078.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0079.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0080.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0081.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0082.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0083.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0084.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0085.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0086.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0087.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0088.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0089.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0090.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0091.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0092.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0093.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0094.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0095.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0096.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0097.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0098.mp3 Normal file

Binary file not shown.

BIN
SD-Karte/mp3/0099.mp3 Normal file

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More