0

So I am working on a project where the board plays a song on a buzzer using PWM and I want the song to stop when i press an external button

typedef enum stateType_enum{
waitPress, debouncePress, waitRelease, debounceRelease
} stateType;
volatile stateType state = waitPress;
volatile bool deviceOn = false;

int main(void){
   sei();
   while(1) {

   switch(state){
     case waitPress:
       break;
     case debouncePress:
       delayMs(100);
       state = waitRelease;
       break;
     case waitRelease:
       break;
     case debounceRelease:
       delayMs(100);
       state = waitPress;
       break;
   }

   if(deviceOn){
       triggerAlarm(&deviceOn);
   }
   _delay_ms(100);
}

ISR(PCINT0_vect){
   if(state == waitPress){
      state = debouncePress;
   }
   else if (state == waitRelease){
      deviceOn = !deviceOn;
      state = debounceRelease;
   }
}

My real question is, can I send the deviceOn as a pointer to the song?

  • Which arduino board do you use and which version of the arduion ide? please show a full sketch, I want to see the function triggerAlarm. Please try to explain what you want to achieve. You can send anything to the song, but that depends on what you want, which I don't understand. Can you change everything and use millis instead of delays? – Jot Apr 9 at 22:24
  • 1
    Please show triggerAlarm()... why do you want to pass it if its argument is a global variable? I think there's no need for that. – Sim Son Apr 9 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.