Moderators: adafruit_support_bill, adafruit
// Plays a full file from beginning to end with no pause.
void playcomplete(char *name) {
// call our helper to find and play this name
playfile(name);
while (wave.isplaying) {
// do nothing while its playing
}
// now its done playing
}
// Plays a full file from beginning to end with no pause.
void playcompleteStopCheck(char *name) {
// call our helper to find and play this name
playfile(name);
while (wave.isplaying) {
if(forceStop == 1):
wave.stop();
}
}
// now its done playing
}
if (interruptAlrm) {
wave.stop();
return; // Alarm was interrupted with button, exitBratan wrote:Brilliant thank you!
Works great, and doesn't require interrupt! I'm just checking button state in the main loop, and once it changes:
- Code: Select all
if (interruptAlrm) {
wave.stop();
return; // Alarm was interrupted with button, exit
You will need to use interrupts to check the buttons. Either a timer interrupt to poll the button, or a pin-change interrupt on the button pin itself.
also.. you already 'are' using the timer/interrupt to execute the 'checkButtons/Switches' function...
if (digitalRead(MENU_BUTTON_PIN) == HIGH)
{
if (soundAlarm) interruptAlrm=true; // Stops Alarm sound
// "Set time" button was pressed;
processMenuButton();
}you can just slap in that new button you want to use into the array, and make the code you want executed once pressed/released...etc..
(leaving your main loop with less overhead to worry about)
SIGNAL(TIMER2_OVF_vect) {
check_switches();
}
Not sure exactly what do you mean by that?
// here is where we define the buttons that we'll use. button "1" is the first, button "6" is the 6th, etc
byte buttons[] = {5, 6, 3, 9, 15, 16};// here is where we define the buttons that we'll use. button "1" is the first, button "6" is the 6th, etc
byte buttons[] = {5, 6, 3, 9, 15, 16, newSwitch};if (pressed[4]) {
playfile("3.WAV");
while (wave.isplaying && pressed[4]) {
//Serial.print(".");
}
wave.stop();
}
if (pressed[5]) {
playfile("4.WAV");
while (wave.isplaying && pressed[5]) {
//Serial.print(".");
}
wave.stop();
}
if (pressed[5]) {
wave.stop();
}
etc..etc
hope this helps..
what I am looking for is a way to write in code
When file (xx.wav) is done playing; {
Perform task here
}
playcomplete(filename);
performtask();
if the sequence listed here is to be performed as the audio is playing, How do you tell it to stop when the audio file is complete?
playfile(name);
while (wave.isplaying)
{
// Perform some task while it is playing
}
// perform some other task when it is finished playing
Return to Arduino Shields from Adafruit
Users browsing this forum: No registered users and 9 guests