Open RobertLRead opened 1 month ago
@RobertLRead I have been refereeing Nagham to the three part article on multi-tasking by Adafruit. Here is part one: https://learn.adafruit.com/multi-tasking-the-arduino-part-1
I believe this article series is so well written as to be the best basis for teaching a new coder better practices and stomping out use of delay() everywhere.
However, I do not know enough about the DFPlayer (I know approximately zero) to know how to avoid blocking calls and how to test for if playing a message is done and other things I assume are going to be required. Further I have never had a formal instruction on designing state variables and well formed state variable names which I anticipate will become increasingly important for coding the KRAKE. I am hoping you can help us develop the required formality.
Lee
https://github.com/nk25719/KiCad-esp32-6leds-2switches-1pj-circuit/tree/main/FIRMWARE
FIRMWARE/BlinkWOdelay_jul16c/BlinkWOdelay_jul16c.ino
Solving this in V2 you can find it at: https://github.com/PubInv/krake/tree/main/Firmware/20240421.V2
Speculation: The long delays in the code which Lee thinks was inherited from examples found on line my be symptomatic of the DFPlayer requiring long delays between command writes. The implication is that many DFPLayers require long delays not just the TD5580A based players.
Much information about the DFPlayer is to be found in this issue of the PMD aka KiCad-esp32-6leds-2switches-1pj-circuit aka homework2 PCB / PWA
https://github.com/nk25719/KiCad-esp32-6leds-2switches-1pj-circuit/issues/55
Here are some easy to read notes about DFPlayers https://reprage.com/posts/2018-05-08-dfplayer-mini-cheat-sheet/
The script after this note looks useful.
I had a bunch of MP3 files and micro SD cards to produce, so I made a little script to make it a bit easier (I had all my sequentially numbered files on the desktop in a folder titled ‘soundFiles’):
#!/bin/bash
mkdir /Volumes/MUSIC/mp3
for filename in ~/Desktop/soundFiles/*.mp3; do
cp $filename /Volumes/MUSIC/mp3/
done
dot_clean /Volumes/MUSIC
Probably, the Arduino freezes completely for 10 minutes in the current code. Short Summary of the expected behavior: We would like the "mute" and "unmute" functions to be usable at any time.
Short Summary of the buggy behavior: Probably when you mute, you can't unmute for 10 minutes.
To Reproduce Steps to reproduce the behavior:
Expected behavior Toggling between muted and unmuted behaviour is possible at any time and that it happens within about 100 ms.
Screenshots The delay below is likely problematic:
if (trackPlaying) { myDFPlayer.pause(); trackPlaying = false; // Allarm paused for 10 minutes delay(600000); // 10 minutes delay Serial.println("ALLARM Paused."); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Alarm Paused"); } else {
Hardware description This occurs on the MockingKrake/PseudoMedicalDevice (PMD)
Additional context Nagham now has a better understanding of using timers to avoid long delays.