From 9629becc54d20b089e5257e7f14dbd0ee412c4e9 Mon Sep 17 00:00:00 2001 From: zzzz Date: Wed, 26 Jun 2024 23:29:43 +0200 Subject: [PATCH] added sounds --- src/SmartSound.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++++ src/main.cpp | 14 ++++++++- 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/src/SmartSound.cpp b/src/SmartSound.cpp index 960f844..f2ba350 100644 --- a/src/SmartSound.cpp +++ b/src/SmartSound.cpp @@ -39,6 +39,82 @@ void SmartSound::playStartSteepingSound() noTone(m_buzzerPin); } +void SmartSound::playTurnOnSound() { + tone(m_buzzerPin, NOTE_C4, 150 * 0.9); + delay(150); + noTone(m_buzzerPin); + + tone(m_buzzerPin, NOTE_D4, 150 * 0.9); + delay(150); + noTone(m_buzzerPin); + + tone(m_buzzerPin, NOTE_A3, 150 * 0.9); + delay(150); + noTone(m_buzzerPin); + + tone(m_buzzerPin, NOTE_D4, 150 * 0.9); + delay(150); + noTone(m_buzzerPin); + + tone(m_buzzerPin, NOTE_D5, 150 * 0.9); + delay(150); + noTone(m_buzzerPin); + + tone(m_buzzerPin, NOTE_C5, 150 * 0.9); + delay(150); + noTone(m_buzzerPin); + + tone(m_buzzerPin, NOTE_C6, 150 * 0.9); + delay(150); + noTone(m_buzzerPin); + + tone(m_buzzerPin, NOTE_C5, 150 * 0.9); + delay(150); + noTone(m_buzzerPin); +} + +void SmartSound::playSaveSound() { + tone(m_buzzerPin, NOTE_D4, 150 * 0.9); + delay(150); + noTone(m_buzzerPin); + + tone(m_buzzerPin, NOTE_A4, 150 * 0.9); + delay(150); + noTone(m_buzzerPin); + + tone(m_buzzerPin, NOTE_D5, 150 * 0.9); + delay(150); + noTone(m_buzzerPin); +} + +void SmartSound::playSuccessSound() { + tone(m_buzzerPin, NOTE_D5, 150 * 0.9); + delay(150); + noTone(m_buzzerPin); + + tone(m_buzzerPin, NOTE_A5, 150 * 0.9); + delay(150); + noTone(m_buzzerPin); +} + +void SmartSound::playFailureSound() { + tone(m_buzzerPin, NOTE_D5, 150 * 0.9); + delay(150); + noTone(m_buzzerPin); + + tone(m_buzzerPin, NOTE_GS3, 150 * 0.9); + delay(150); + noTone(m_buzzerPin); +} + +void SmartSound::playTeaReadySound() { + playStartSteepingSound(); + delay(200); + playStartSteepingSound(); + delay(200); + playStartSteepingSound(); +} + void SmartSound::play(Sound sound, int tempo) { switch (sound) diff --git a/src/main.cpp b/src/main.cpp index cbbeb63..57bf584 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -52,6 +52,7 @@ unsigned long timeoutTimeMillis; #define CATCH_NET_FAILURE(netResult, msg) \ if (netResult == JSON.parse("{}")) \ { \ + sound.playFailureSound(); \ smartDisplay.printMsg(msg); \ delay(500); \ break; \ @@ -79,6 +80,8 @@ void setup() { Serial.begin(9600); + sound.playTurnOnSound(); + smartServo.moveServoToZero(); smartStrip.init(); @@ -96,7 +99,6 @@ void setup() teaNet.init(ssid, password); - // load config JSONVar result = teaNet.httpsGETRequest(shuttleServer + "/configuration"); // catch possible failure @@ -179,6 +181,7 @@ void loop() } case PROCESS_RFID_SCAN: { + sound.playSuccessSound(); smartDisplay.playTeaAnimationPartOne(32, "", "Loading...", "", ""); Serial.println(currentTea.m_rfidCode); @@ -269,6 +272,7 @@ void loop() // abort if red button pressed if (buttonLeft.isDown() && buttonRight.isDown()) { + sound.playFailureSound(); teaTimer.endSteeping(); smartDisplay.printMsg("Aborting..."); smartStrip.animateBottomToTop(1, 0, 0); @@ -287,6 +291,7 @@ void loop() else { smartDisplay.printMsg("Ready!"); + sound.playTeaReadySound(); smartStrip.animateBottomToTop(0, 1, 0); state = State::REQUEST_FEEDBACK; timeoutTimeMillis = millis() + (feedbackTimeoutSeconds * 1000); @@ -341,6 +346,7 @@ void loop() if (isTouchBtnPressed()) { + sound.playSuccessSound(); smartDisplay.playTeaAnimationPartOne(32, "Accepted!", "(perfect)", "", "saving..."); // keep steeping time for next brew @@ -359,6 +365,7 @@ void loop() } if (buttonLeft.isJustPressed()) { + sound.playSuccessSound(); // decrease steeping time for next brew smartDisplay.playTeaAnimationPartOne(32, "Accepted!", "(shorter)", "", "saving..."); @@ -385,6 +392,7 @@ void loop() } if (buttonRight.isJustPressed()) { + sound.playSuccessSound(); // increase steeping time for next brew smartDisplay.playTeaAnimationPartOne(32, "Accepted!", "(longer)", "", "saving..."); @@ -431,10 +439,13 @@ void loop() { currentTea.m_steepingSeconds = 0; } + else + sound.playMinusSound(); } if (buttonRight.isJustPressed()) { currentTea.m_steepingSeconds += 10; + sound.playPlusSound(); } if (isTouchBtnPressed()) @@ -446,6 +457,7 @@ void loop() CATCH_NET_FAILURE(result, "POST FAILED") + sound.playSaveSound(); smartDisplay.playTeaAnimationPartTwo(32, "", "Done!", "", ""); state = State::DISPLAY_SCANNED_TEA_CONFIG; }