Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Visual Micro is in vMicro>General>Tutorial Mode
- //
- /*
- Name: TonuinoProjekt.ino
- Created: 31.10.2018 11:19:23
- Author: (c) Thorsten Voß
- */
- // Define User Types below here or use a .h file
- //
- // Define Function Prototypes that use User Types below here or use a .h file
- //
- #include <stdint.h>
- #include <DFMiniMp3.h>
- #include <EEPROM.h>
- #include <JC_Button.h>
- #include <MFRC522.h>
- #include <SPI.h>
- #include <SoftwareSerial.h>
- // Define Functions below here or use other .ino or cpp files
- //
- // constants and variables
- //
- uint8_t maxVolume; // maximal volume of DFPlayer Mini
- uint8_t minVolume; // minimal volume of DFPlayer Mini
- uint8_t initVolume; // initial volume of DFPlayer Mini
- uint8_t playMode; // play mode 1=Admin, 2=Config, 3= Play
- short cancelFunc; // Ask for Cancel
- // this object stores nfc tag data
- struct nfcTagObject {
- uint32_t cookie;
- uint8_t version;
- uint8_t folder;
- uint8_t mode;
- uint8_t special;
- };
- struct nfcTagObject myCard;
- // DFPlayer Mini
- SoftwareSerial mySoftwareSerial(2, 3); // RX, TX
- uint16_t numTracksInFolder;
- uint16_t currentTrack;
- static void nextTrack(uint16_t track);
- int voiceMenu(int numberOfOptions, int startMessage, int messageOffset,
- bool preview = false, int previewFromFolder = 0);
- bool knownCard = false;
- int voiceMenuSpecial(int firstMsg, int lastMsg, int startMsg);
- void playMp3File(short mp3Number);
- void adminCard(short adminFunc);
- // 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(track);
- }
- 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 uint16_t _lastTrackFinished;
- // 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
- MFRC522::MIFARE_Key key;
- bool successRead;
- byte sector = 1;
- byte blockAddr = 4;
- byte trailerBlock = 7;
- MFRC522::StatusCode status;
- #define buttonPause A0
- #define buttonUp A1
- #define buttonDown A2
- #define busyPin 4
- #define LONG_PRESS 1000
- Button pauseButton(buttonPause);
- Button upButton(buttonUp);
- Button downButton(buttonDown);
- bool ignorePauseButton = false;
- bool ignoreUpButton = false;
- bool ignoreDownButton = false;
- uint8_t numberOfCards = 0;
- bool isPlaying() { return !digitalRead(busyPin); }
- // The setup() function runs once each time the micro-controller starts
- //
- void setup() {
- Serial.begin(115200); // Es gibt ein paar Debug Ausgaben über die serielle
- // Schnittstelle
- randomSeed(analogRead(A0)); // Zufallsgenerator initialisieren
- Serial.println(F("TonUINO Version 2.0a"));
- Serial.println(F("(c) Thorsten Voß"));
- // Knöpfe mit PullUp
- pinMode(buttonPause, INPUT_PULLUP);
- pinMode(buttonUp, INPUT_PULLUP);
- pinMode(buttonDown, INPUT_PULLUP);
- // Busy Pin
- pinMode(busyPin, INPUT);
- // init Volume
- maxVolume = EEPROM.read(101);
- minVolume = EEPROM.read(102);
- initVolume = EEPROM.read(103);
- playMode = EEPROM.read(104);
- Serial.print("Max Volume = ");
- Serial.println(maxVolume);
- Serial.print("Min Volume = ");
- Serial.println(minVolume);
- Serial.print("Init Volume = ");
- Serial.println(initVolume);
- Serial.print("Play Mode = ");
- Serial.println(playMode);
- if (maxVolume < 1 || maxVolume > 30) {
- maxVolume = 15;
- EEPROM.write(101, maxVolume);
- }
- if (minVolume < 1 || minVolume > 30) {
- minVolume = 5;
- EEPROM.write(102, minVolume);
- }
- if (initVolume < 1 || initVolume > 30) {
- initVolume = 10;
- EEPROM.write(103, initVolume);
- }
- //playMode = 9;
- if (playMode < 1 || playMode > 3) {
- playMode = 1;
- EEPROM.write(104, playMode);
- }
- // DFPlayer Mini initialisieren
- mp3.begin();
- mp3.setVolume(initVolume);
- //----Set EQ----
- mp3.setEq(DfMp3_Eq_Normal);
- // mp3.setEq(DfMp3_Eq_Pop);
- // mp3.setEq(DfMp3_Eq_Rock);
- // mp3.setEq(DfMp3_Eq_Jazz);
- // mp3.setEq(DfMp3_Eq_Classic);
- // mp3.setEq(DfMp3_Eq_Bass);
- // NFC Leser initialisieren
- SPI.begin(); // Init SPI bus
- mfrc522.PCD_Init(); // Init MFRC522
- mfrc522
- .PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader
- for (byte i = 0; i < 6; i++) {
- key.keyByte[i] = 0xFF;
- }
- // 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);
- }
- }
- mp3.playMp3FolderTrack(950);
- delay(3000);
- mp3.playMp3FolderTrack(900);
- }
- // Add the main program code into the continuous loop() function
- //
- void loop() {
- do {
- mp3.loop();
- // Buttons werden nun über JS_Button gehandelt, dadurch kann jede Taste
- // doppelt belegt werden
- pauseButton.read();
- upButton.read();
- downButton.read();
- if (pauseButton.wasReleased()) {
- if (ignorePauseButton == false)
- if (isPlaying())
- mp3.pause();
- else
- mp3.start();
- ignorePauseButton = false;
- }
- else if (pauseButton.pressedFor(LONG_PRESS) &&
- ignorePauseButton == false) {
- if (isPlaying()) {
- mp3.playAdvertisement(910);
- delay(2000);
- mp3.playAdvertisement(myCard.folder);
- delay(2000);
- mp3.playAdvertisement(911);
- delay(2000);
- mp3.playAdvertisement(currentTrack);
- }
- else if (playMode < 3) {
- knownCard = false;
- mp3.playMp3FolderTrack(800);
- Serial.println(F("Karte resetten..."));
- resetCard();
- mfrc522.PICC_HaltA();
- mfrc522.PCD_StopCrypto1();
- }
- ignorePauseButton = true;
- }
- if (upButton.pressedFor(LONG_PRESS)) {
- Serial.println(F("Volume Up"));
- if (mp3.getVolume() < maxVolume) {
- mp3.increaseVolume();
- delay(200);
- }
- ignoreUpButton = true;
- }
- else if (upButton.wasReleased()) {
- if (!ignoreUpButton)
- nextTrack(random(65536));
- else
- ignoreUpButton = false;
- }
- if (downButton.pressedFor(LONG_PRESS)) {
- Serial.println(F("Volume Down"));
- if (mp3.getVolume() > minVolume) {
- mp3.decreaseVolume();
- delay(200);
- }
- ignoreDownButton = true;
- }
- else if (downButton.wasReleased()) {
- if (!ignoreDownButton)
- previousTrack();
- else
- ignoreDownButton = false;
- }
- // Ende der Buttons
- } while (!mfrc522.PICC_IsNewCardPresent());
- // RFID Karte wurde aufgelegt
- //if (playMode == 3)
- // return;
- if (!mfrc522.PICC_ReadCardSerial())
- return;
- if (readCard(&myCard) == true) {
- if (myCard.cookie == 322417479 && myCard.folder != 0 && myCard.mode != 0) {
- knownCard = true;
- _lastTrackFinished = 0;
- numTracksInFolder = mp3.getFolderTrackCount(myCard.folder);
- Serial.print(numTracksInFolder);
- Serial.print(F(" Dateien in Ordner "));
- Serial.println(myCard.folder);
- // Hörspielmodus: eine zufällige Datei aus dem Ordner
- if (myCard.mode == 1) {
- Serial.println(F("Hörspielmodus -> zufälligen Track wiedergeben"));
- currentTrack = random(1, numTracksInFolder + 1);
- Serial.println(currentTrack);
- mp3.playFolderTrack(myCard.folder, currentTrack);
- }
- // Album Modus: kompletten Ordner spielen
- if (myCard.mode == 2) {
- Serial.println(F("Album Modus -> kompletten Ordner wiedergeben"));
- currentTrack = 1;
- mp3.playFolderTrack(myCard.folder, currentTrack);
- }
- // Party Modus: Ordner in zufälliger Reihenfolge
- if (myCard.mode == 3) {
- Serial.println(
- F("Party Modus -> Ordner in zufälliger Reihenfolge wiedergeben"));
- currentTrack = random(1, numTracksInFolder + 1);
- mp3.playFolderTrack(myCard.folder, currentTrack);
- }
- // Einzel Modus: eine Datei aus dem Ordner abspielen
- if (myCard.mode == 4) {
- Serial.println(
- F("Einzel Modus -> eine Datei aus dem Odrdner abspielen"));
- currentTrack = myCard.special;
- mp3.playFolderTrack(myCard.folder, currentTrack);
- }
- // Hörbuch Modus: kompletten Ordner spielen und Fortschritt merken
- if (myCard.mode == 5) {
- Serial.println(F("Hörbuch Modus -> kompletten Ordner spielen und "
- "Fortschritt merken"));
- currentTrack = EEPROM.read(myCard.folder);
- mp3.playFolderTrack(myCard.folder, currentTrack);
- }
- // Administratorkarte
- if (myCard.mode == 6) {
- // Administratorfunktion 1
- if (myCard.special == 1) {
- adminCard(myCard.special);
- }
- }
- // Testkarte
- if (myCard.mode == 7) {
- // Testkartenfunktion
- if (myCard.special == 1) {
- testCard();
- }
- }
- }
- // Neue Karte konfigurieren
- else if (playMode < 3) {
- knownCard = false;
- setupCard();
- }
- }
- mfrc522.PICC_HaltA();
- mfrc522.PCD_StopCrypto1();
- }
- // nextTrack Function
- //
- static void nextTrack(uint16_t track) {
- if (track == _lastTrackFinished) {
- return;
- }
- _lastTrackFinished = track;
- if (knownCard == 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 -> keinen neuen Track spielen"));
- // mp3.sleep(); // Je nach Modul kommt es nicht mehr zurück aus dem Sleep!
- }
- if (myCard.mode == 2) {
- if (currentTrack != numTracksInFolder) {
- currentTrack = currentTrack + 1;
- mp3.playFolderTrack(myCard.folder, currentTrack);
- Serial.print(F("Albummodus ist aktiv -> nächster Track: "));
- Serial.print(currentTrack);
- }
- else
- // mp3.sleep(); // Je nach Modul kommt es nicht mehr zurück aus dem Sleep!
- {
- }
- }
- if (myCard.mode == 3) {
- currentTrack = random(1, numTracksInFolder + 1);
- Serial.print(F("Party Modus ist aktiv -> zufälligen Track spielen: "));
- Serial.println(currentTrack);
- mp3.playFolderTrack(myCard.folder, currentTrack);
- }
- if (myCard.mode == 4) {
- Serial.println(F("Einzel Modus aktiv -> Strom sparen"));
- // mp3.sleep(); // Je nach Modul kommt es nicht mehr zurück aus dem Sleep!
- }
- if (myCard.mode == 5) {
- if (currentTrack != numTracksInFolder) {
- currentTrack = currentTrack + 1;
- Serial.print(F("Hörbuch Modus ist aktiv -> nächster Track und "
- "Fortschritt speichern"));
- Serial.println(currentTrack);
- mp3.playFolderTrack(myCard.folder, currentTrack);
- // Fortschritt im EEPROM abspeichern
- EEPROM.write(myCard.folder, currentTrack);
- }
- else {
- // mp3.sleep(); // Je nach Modul kommt es nicht mehr zurück aus dem Sleep!
- // Fortschritt zurück setzen
- EEPROM.write(myCard.folder, 1);
- }
- }
- }
- // previousTrack Function
- //
- static void previousTrack() {
- if (myCard.mode == 1) {
- Serial.println(F("Hörspielmodus ist aktiv -> Track von vorne spielen"));
- mp3.playFolderTrack(myCard.folder, currentTrack);
- }
- if (myCard.mode == 2) {
- Serial.println(F("Albummodus ist aktiv -> vorheriger Track"));
- if (currentTrack != 1) {
- currentTrack = currentTrack - 1;
- }
- mp3.playFolderTrack(myCard.folder, currentTrack);
- }
- if (myCard.mode == 3) {
- Serial.println(F("Party Modus ist aktiv -> Track von vorne spielen"));
- mp3.playFolderTrack(myCard.folder, currentTrack);
- }
- if (myCard.mode == 4) {
- Serial.println(F("Einzel Modus aktiv -> Track von vorne spielen"));
- mp3.playFolderTrack(myCard.folder, currentTrack);
- }
- if (myCard.mode == 5) {
- Serial.println(F("Hörbuch Modus ist aktiv -> vorheriger Track und "
- "Fortschritt speichern"));
- if (currentTrack != 1) {
- currentTrack = currentTrack - 1;
- }
- mp3.playFolderTrack(myCard.folder, currentTrack);
- // Fortschritt im EEPROM abspeichern
- EEPROM.write(myCard.folder, currentTrack);
- }
- }
- // voiceMenu Function
- //
- int voiceMenu(int numberOfOptions, int startMessage, int messageOffset,
- bool preview = false, int previewFromFolder = 0) {
- int returnValue = 0;
- if (startMessage != 0)
- mp3.playMp3FolderTrack(startMessage);
- do {
- pauseButton.read();
- upButton.read();
- downButton.read();
- mp3.loop();
- if (pauseButton.wasPressed()) {
- if (returnValue != 0)
- return returnValue;
- delay(1000);
- }
- if (upButton.pressedFor(LONG_PRESS)) {
- returnValue = min(returnValue + 10, numberOfOptions);
- mp3.playMp3FolderTrack(messageOffset + returnValue);
- delay(1000);
- if (preview) {
- do {
- delay(10);
- } while (isPlaying());
- if (previewFromFolder == 0)
- mp3.playFolderTrack(returnValue, 1);
- else
- mp3.playFolderTrack(previewFromFolder, returnValue);
- }
- ignoreUpButton = true;
- }
- else if (upButton.wasReleased()) {
- if (!ignoreUpButton) {
- returnValue = min(returnValue + 1, numberOfOptions);
- mp3.playMp3FolderTrack(messageOffset + returnValue);
- delay(1000);
- if (preview) {
- do {
- delay(10);
- } while (isPlaying());
- if (previewFromFolder == 0)
- mp3.playFolderTrack(returnValue, 1);
- else
- mp3.playFolderTrack(previewFromFolder, returnValue);
- }
- }
- else
- ignoreUpButton = false;
- }
- if (downButton.pressedFor(LONG_PRESS)) {
- returnValue = max(returnValue - 10, 1);
- mp3.playMp3FolderTrack(messageOffset + returnValue);
- delay(1000);
- if (preview) {
- do {
- delay(10);
- } while (isPlaying());
- if (previewFromFolder == 0)
- mp3.playFolderTrack(returnValue, 1);
- else
- mp3.playFolderTrack(previewFromFolder, returnValue);
- }
- ignoreDownButton = true;
- }
- else if (downButton.wasReleased()) {
- if (!ignoreDownButton) {
- returnValue = max(returnValue - 1, 1);
- mp3.playMp3FolderTrack(messageOffset + returnValue);
- delay(1000);
- if (preview) {
- do {
- delay(10);
- } while (isPlaying());
- if (previewFromFolder == 0)
- mp3.playFolderTrack(returnValue, 1);
- else
- mp3.playFolderTrack(previewFromFolder, returnValue);
- }
- }
- else
- ignoreDownButton = false;
- }
- } while (true);
- }
- // voiceMenuSpecial Function - für Lautstärkeänderung zum beliebigen Aufsetzen
- //
- //int voiceMenu(int numberOfOptions, int startMessage, int messageOffset,
- // bool preview = false, int previewFromFolder = 0)
- int voiceMenuSpecial(int firstMsg, int lastMsg, int startMsg) {
- int returnValue = 0;
- mp3.playMp3FolderTrack(startMsg);
- returnValue = startMsg;
- do {
- pauseButton.read();
- upButton.read();
- downButton.read();
- mp3.loop();
- if (pauseButton.wasPressed()) {
- return returnValue;
- delay(1000);
- }
- if (upButton.wasReleased()) {
- if (!ignoreUpButton) {
- returnValue = min(returnValue + 1, lastMsg);
- mp3.playMp3FolderTrack(returnValue);
- delay(1000);
- }
- else
- ignoreUpButton = false;
- }
- if (downButton.wasReleased()) {
- if (!ignoreDownButton) {
- returnValue = max(returnValue - 1, firstMsg);
- mp3.playMp3FolderTrack(returnValue);
- delay(1000);
- }
- else
- ignoreDownButton = false;
- }
- } while (true);
- }
- // resetCard Function
- //
- void resetCard() {
- do {
- pauseButton.read();
- upButton.read();
- downButton.read();
- if (upButton.wasReleased() || downButton.wasReleased()) {
- Serial.print(F("Abgebrochen!"));
- mp3.playMp3FolderTrack(802);
- return;
- }
- } while (!mfrc522.PICC_IsNewCardPresent());
- if (!mfrc522.PICC_ReadCardSerial()) {
- Serial.print(F("Falsche Karte!"));
- return;
- }
- Serial.print(F("Karte wird neu Konfiguriert!"));
- setupCard();
- }
- // setupCard Function
- //
- void setupCard() {
- mp3.pause();
- Serial.print(F("Neue Karte konfigurieren"));
- // Abbruch abfragen
- mp3.playMp3FolderTrack(350);
- do {
- pauseButton.read();
- upButton.read();
- downButton.read();
- if (upButton.wasReleased() || downButton.wasReleased()) {
- Serial.print(F("Abgebrochen!"));
- mp3.playMp3FolderTrack(802);
- return;
- }
- } while (!pauseButton.wasPressed());
- // Ordner abfragen
- myCard.folder = voiceMenu(99, 300, 0, true);
- // Wiedergabemodus abfragen
- if (playMode == 1) {
- myCard.mode = voiceMenu(7, 310, 310);
- }
- else {
- myCard.mode = voiceMenu(5, 310, 310);
- }
- // Einzelmodus -> Datei abfragen
- if (myCard.mode == 4)
- myCard.special = voiceMenu(mp3.getFolderTrackCount(myCard.folder), 320, 0,
- true, myCard.folder);
- // Hörbuchmodus -> Fortschritt im EEPROM auf 1 setzen
- if (myCard.mode == 5)
- EEPROM.write(myCard.folder, 1);
- // Admin Funktionen, create Admin Card
- if (myCard.mode == 6) {
- myCard.folder = 1;
- myCard.special = 1;
- Serial.print(F("Administratorkarte erstellt"));
- }
- // Test Funktionen, create Test Card
- if (myCard.mode == 7) {
- myCard.folder = 1;
- myCard.special = 1;
- Serial.print(F("Testkarte erstellt"));
- }
- // Karte ist konfiguriert -> speichern
- mp3.pause();
- writeCard(myCard);
- }
- // readCard Function
- //
- bool readCard(struct nfcTagObject *nfcTag) {
- bool returnValue = true;
- // Show some details of the PICC (that is: the tag/card)
- Serial.print(F("Card UID:"));
- dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
- Serial.println();
- Serial.print(F("PICC type: "));
- MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
- Serial.println(mfrc522.PICC_GetTypeName(piccType));
- byte buffer[18];
- byte size = sizeof(buffer);
- // Authenticate using key A
- Serial.println(F("Authenticating using key A..."));
- status = (MFRC522::StatusCode)mfrc522.PCD_Authenticate(
- MFRC522::PICC_CMD_MF_AUTH_KEY_A, trailerBlock, &key, &(mfrc522.uid));
- if (status != MFRC522::STATUS_OK) {
- returnValue = false;
- Serial.print(F("PCD_Authenticate() failed: "));
- Serial.println(mfrc522.GetStatusCodeName(status));
- return;
- }
- // Show the whole sector as it currently is
- Serial.println(F("Current data in sector:"));
- mfrc522.PICC_DumpMifareClassicSectorToSerial(&(mfrc522.uid), &key, sector);
- Serial.println();
- // Read data from the block
- Serial.print(F("Reading data from block "));
- Serial.print(blockAddr);
- Serial.println(F(" ..."));
- status = (MFRC522::StatusCode)mfrc522.MIFARE_Read(blockAddr, buffer, &size);
- if (status != MFRC522::STATUS_OK) {
- returnValue = false;
- Serial.print(F("MIFARE_Read() failed: "));
- Serial.println(mfrc522.GetStatusCodeName(status));
- }
- Serial.print(F("Data in block "));
- Serial.print(blockAddr);
- Serial.println(F(":"));
- dump_byte_array(buffer, 16);
- Serial.println();
- Serial.println();
- uint32_t tempCookie;
- tempCookie = (uint32_t)buffer[0] << 24;
- tempCookie += (uint32_t)buffer[1] << 16;
- tempCookie += (uint32_t)buffer[2] << 8;
- tempCookie += (uint32_t)buffer[3];
- nfcTag->cookie = tempCookie;
- nfcTag->version = buffer[4];
- nfcTag->folder = buffer[5];
- nfcTag->mode = buffer[6];
- nfcTag->special = buffer[7];
- return returnValue;
- }
- // writeCard Function
- //
- void writeCard(struct nfcTagObject nfcTag) {
- MFRC522::PICC_Type mifareType;
- byte buffer[16] = { 0x13, 0x37, 0xb3, 0x47, // 0x1337 0xb347 magic cookie to
- // identify our nfc tags
- 0x01, // version 1
- nfcTag.folder, // the folder picked by the user
- nfcTag.mode, // the playback mode picked by the user
- nfcTag.special, // track or function for admin cards
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- byte size = sizeof(buffer);
- mifareType = mfrc522.PICC_GetType(mfrc522.uid.sak);
- // Authenticate using key B
- Serial.println(F("Authenticating again using key B..."));
- status = (MFRC522::StatusCode)mfrc522.PCD_Authenticate(
- MFRC522::PICC_CMD_MF_AUTH_KEY_B, trailerBlock, &key, &(mfrc522.uid));
- if (status != MFRC522::STATUS_OK) {
- Serial.print(F("PCD_Authenticate() failed: "));
- Serial.println(mfrc522.GetStatusCodeName(status));
- mp3.playMp3FolderTrack(401);
- return;
- }
- // Write data to the block
- Serial.print(F("Writing data into block "));
- Serial.print(blockAddr);
- Serial.println(F(" ..."));
- dump_byte_array(buffer, 16);
- Serial.println();
- status = (MFRC522::StatusCode)mfrc522.MIFARE_Write(blockAddr, buffer, 16);
- if (status != MFRC522::STATUS_OK) {
- Serial.print(F("MIFARE_Write() failed: "));
- Serial.println(mfrc522.GetStatusCodeName(status));
- mp3.playMp3FolderTrack(401);
- }
- else
- mp3.playMp3FolderTrack(400);
- Serial.println();
- delay(100);
- }
- // adminCard Function
- //
- void adminCard(short adminFunc) {
- int adminSubFunc;
- int adminMode;
- uint8_t oldMaxVolume;
- uint8_t oldMinVolume;
- uint8_t oldInitVolume;
- uint8_t oldPlayMode;
- oldMaxVolume = maxVolume;
- oldMinVolume = minVolume;
- oldInitVolume = initVolume;
- oldPlayMode = playMode;
- mp3.pause();
- Serial.print("Administratorkarte aufgelegt");
- if (adminFunc == 1) {
- adminSubFunc = voiceMenu(5, 500, 500);
- if (adminSubFunc == 1) {
- Serial.print("Max Volume");
- mp3.playMp3FolderTrack(511);
- delay(2000);
- mp3.playMp3FolderTrack(maxVolume);
- delay(1000);
- mp3.playMp3FolderTrack(900);
- maxVolume = voiceMenuSpecial(10, 30, maxVolume);
- minVolume = min(minVolume, maxVolume);
- initVolume = min(initVolume, maxVolume);
- }
- else if (adminSubFunc == 2) {
- Serial.print("Min Volume");
- mp3.playMp3FolderTrack(512);
- delay(2000);
- mp3.playMp3FolderTrack(minVolume);
- delay(1000);
- mp3.playMp3FolderTrack(900);
- minVolume = min(minVolume, maxVolume);
- minVolume = voiceMenuSpecial(5, max(15, maxVolume), minVolume);
- maxVolume = max(maxVolume, minVolume);
- initVolume = max(initVolume, minVolume);
- }
- else if (adminSubFunc == 3) {
- Serial.print("Init Volume");
- mp3.playMp3FolderTrack(513);
- delay(2000);
- mp3.playMp3FolderTrack(initVolume);
- delay(1000);
- mp3.playMp3FolderTrack(900);
- initVolume = min(initVolume, maxVolume);
- initVolume = max(initVolume, minVolume);
- initVolume = voiceMenuSpecial(minVolume, maxVolume, initVolume);
- maxVolume = max(maxVolume, initVolume);
- minVolume = min(minVolume, initVolume);
- }
- else if (adminSubFunc == 4) {
- Serial.print("Modus auswählen");
- adminMode = voiceMenu(5, 520, 520);
- playMode = adminMode;
- }
- else if (adminSubFunc == 5) {
- Serial.print("Administration abgebrochen");
- }
- }
- if (adminSubFunc >= 1 && adminSubFunc <= 3) {
- Serial.print(maxVolume);
- Serial.println(F("=Max"));
- Serial.print(minVolume);
- Serial.println(F("=Min"));
- Serial.print(initVolume);
- Serial.println(F("=Init"));
- mp3.playMp3FolderTrack(511);
- delay(2000);
- mp3.playMp3FolderTrack(maxVolume);
- delay(1000);
- mp3.playMp3FolderTrack(900);
- if (oldMaxVolume != maxVolume) {
- EEPROM.write(101, maxVolume);
- }
- delay(1000);
- mp3.playMp3FolderTrack(512);
- delay(2000);
- mp3.playMp3FolderTrack(minVolume);
- delay(1000);
- mp3.playMp3FolderTrack(900);
- if (oldMinVolume != minVolume) {
- EEPROM.write(102, minVolume);
- }
- delay(1000);
- mp3.playMp3FolderTrack(513);
- delay(2000);
- mp3.playMp3FolderTrack(initVolume);
- delay(1000);
- mp3.playMp3FolderTrack(900);
- if (oldInitVolume != initVolume) {
- EEPROM.write(103, initVolume);
- }
- }
- if (adminSubFunc == 4) {
- mp3.playMp3FolderTrack(514);
- delay(2000);
- if (playMode == 1) {
- mp3.playMp3FolderTrack(521);
- }
- else if (playMode == 1) {
- mp3.playMp3FolderTrack(522);
- }
- else if (playMode == 1) {
- mp3.playMp3FolderTrack(523);
- }
- delay(1000);
- mp3.playMp3FolderTrack(900);
- if (oldPlayMode != playMode) {
- EEPROM.write(104, playMode);
- }
- }
- mp3.playMp3FolderTrack(599);
- delay(2000);
- mp3.playMp3FolderTrack(900);
- mp3.pause();
- }
- /**
- * Helper routine to dump a byte array as hex values to Serial.
- */
- void dump_byte_array(byte *buffer, byte bufferSize) {
- for (byte i = 0; i < bufferSize; i++) {
- Serial.print(buffer[i] < 0x10 ? " 0" : " ");
- Serial.print(buffer[i], HEX);
- }
- }
- // playMp3File - Zahlen zusammensetzen
- //
- void playMp3File(short mp3Number) {
- //mp3.playAdvertisement(mp3Number);
- mp3.playMp3FolderTrack(mp3Number);
- do {
- delay(100);
- } while (isPlaying());
- }
- // Test Function
- //
- void testCard() {
- Serial.println(F("Testkarte aufgelegt"));
- mp3.pause();
- playMp3File(7);
- playMp3File(100);
- playMp3File(7);
- playMp3File(80);
- playMp3File(400);
- playMp3File(400);
- playMp3File(8);
- playMp3File(900);
- mp3.pause();
- Serial.println(F("Test Ende"));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement