From 663ee1cf2a59c7a2299713561f465ddc83f166ed Mon Sep 17 00:00:00 2001 From: Markus Schlotterer Date: Wed, 13 Jan 2021 18:36:54 +0100 Subject: [PATCH 1/3] Added code to control extra load on D6 --- Tonuino.ino | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/Tonuino.ino b/Tonuino.ino index c3ce9c9b..a85849bf 100644 --- a/Tonuino.ino +++ b/Tonuino.ino @@ -68,6 +68,7 @@ adminSettings mySettings; nfcTagObject myCard; folderSettings *myFolder; unsigned long sleepAtMillis = 0; +unsigned long toogleLoadAtMillis = 0; static uint16_t _lastTrackFinished; static void nextTrack(uint16_t track); @@ -79,6 +80,7 @@ void writeCard(nfcTagObject nfcTag); void dump_byte_array(byte * buffer, byte bufferSize); void adminMenu(bool fromCard = false); bool knownCard = false; +void disableLoadTimer(); // implement a notification class, // its member methods will get called @@ -643,6 +645,7 @@ MFRC522::StatusCode status; #define buttonDown A2 #define busyPin 4 #define shutdownPin 7 +#define loadPin 6 #define openAnalogPin A7 #ifdef FIVEBUTTONS @@ -652,6 +655,9 @@ MFRC522::StatusCode status; #define LONG_PRESS 1000 +#define LOAD_ON 150 +#define LOAD_OFF 4800 + Button pauseButton(buttonPause); Button upButton(buttonUp); Button downButton(buttonDown); @@ -688,6 +694,7 @@ void checkStandbyAtMillis() { Serial.println(F("=== power off!")); // enter sleep state digitalWrite(shutdownPin, HIGH); + disableLoadTimer(); delay(500); // http://discourse.voss.earth/t/intenso-s10000-powerbank-automatische-abschaltung-software-only/805 @@ -702,6 +709,32 @@ void checkStandbyAtMillis() { } } +void setLoadTimer() { + Serial.println(F("=== setLoadTimer()")); + toogleLoadAtMillis = millis() + LOAD_ON; + digitalWrite(loadPin, HIGH); + Serial.println(toogleLoadAtMillis); +} + +void disableLoadTimer() { + Serial.println(F("=== disableLoadTimer()")); + toogleLoadAtMillis = 0; + digitalWrite(loadPin, LOW); +} + +void checkLoadTimer() { + if (toogleLoadAtMillis != 0 && millis() > toogleLoadAtMillis) { + if (digitalRead(loadPin) == HIGH) { + toogleLoadAtMillis = millis() + LOAD_OFF; + digitalWrite(loadPin, LOW); + } + else { + toogleLoadAtMillis = millis() + LOAD_ON; + digitalWrite(loadPin, HIGH); + } + } +} + bool isPlaying() { return !digitalRead(busyPin); } @@ -778,6 +811,9 @@ void setup() { pinMode(shutdownPin, OUTPUT); digitalWrite(shutdownPin, LOW); + // Start load timer + pinMode(loadPin, OUTPUT); + setLoadTimer(); // RESET --- ALLE DREI KNÖPFE BEIM STARTEN GEDRÜCKT HALTEN -> alle EINSTELLUNGEN werden gelöscht if (digitalRead(buttonPause) == LOW && digitalRead(buttonUp) == LOW && @@ -948,6 +984,7 @@ void playShortCut(uint8_t shortCut) { void loop() { do { checkStandbyAtMillis(); + checkLoadTimer(); mp3.loop(); // Modifier : WIP! From 06d4f53edf1b1581a739245816068394e99df40c Mon Sep 17 00:00:00 2001 From: Markus Schlotterer Date: Wed, 13 Jan 2021 20:32:42 +0100 Subject: [PATCH 2/3] Disable when LOAD_ON = LOAD_OFF = 0, permanent on when LOAD_OFF = 0 and LOAD_ON > 0 --- Tonuino.ino | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Tonuino.ino b/Tonuino.ino index a85849bf..3c4d33fc 100644 --- a/Tonuino.ino +++ b/Tonuino.ino @@ -655,6 +655,7 @@ MFRC522::StatusCode status; #define LONG_PRESS 1000 +// Set both to 0 to disable, set only LOAD_OFF to 0 for permanent ON #define LOAD_ON 150 #define LOAD_OFF 4800 @@ -711,8 +712,12 @@ void checkStandbyAtMillis() { void setLoadTimer() { Serial.println(F("=== setLoadTimer()")); - toogleLoadAtMillis = millis() + LOAD_ON; - digitalWrite(loadPin, HIGH); + if (LOAD_ON > 0 && LOAD_OFF > 0) { + toogleLoadAtMillis = millis() + LOAD_ON; + } + if (LOAD_ON > 0) { + digitalWrite(loadPin, HIGH); + } Serial.println(toogleLoadAtMillis); } From 1bafb3f4a3f95b0a8bdefecc5d3e0951c26e17ab Mon Sep 17 00:00:00 2001 From: Markus Schlotterer Date: Wed, 13 Jan 2021 21:00:38 +0100 Subject: [PATCH 3/3] Corrected misspelling --- Tonuino.ino | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Tonuino.ino b/Tonuino.ino index 3c4d33fc..355f3111 100644 --- a/Tonuino.ino +++ b/Tonuino.ino @@ -68,7 +68,7 @@ adminSettings mySettings; nfcTagObject myCard; folderSettings *myFolder; unsigned long sleepAtMillis = 0; -unsigned long toogleLoadAtMillis = 0; +unsigned long toggleLoadAtMillis = 0; static uint16_t _lastTrackFinished; static void nextTrack(uint16_t track); @@ -713,28 +713,28 @@ void checkStandbyAtMillis() { void setLoadTimer() { Serial.println(F("=== setLoadTimer()")); if (LOAD_ON > 0 && LOAD_OFF > 0) { - toogleLoadAtMillis = millis() + LOAD_ON; + toggleLoadAtMillis = millis() + LOAD_ON; } if (LOAD_ON > 0) { digitalWrite(loadPin, HIGH); } - Serial.println(toogleLoadAtMillis); + Serial.println(toggleLoadAtMillis); } void disableLoadTimer() { Serial.println(F("=== disableLoadTimer()")); - toogleLoadAtMillis = 0; + toggleLoadAtMillis = 0; digitalWrite(loadPin, LOW); } void checkLoadTimer() { - if (toogleLoadAtMillis != 0 && millis() > toogleLoadAtMillis) { + if (toggleLoadAtMillis != 0 && millis() > toggleLoadAtMillis) { if (digitalRead(loadPin) == HIGH) { - toogleLoadAtMillis = millis() + LOAD_OFF; + toggleLoadAtMillis = millis() + LOAD_OFF; digitalWrite(loadPin, LOW); } else { - toogleLoadAtMillis = millis() + LOAD_ON; + toggleLoadAtMillis = millis() + LOAD_ON; digitalWrite(loadPin, HIGH); } }