Hello,
I'm new to arduino programming so please be gentle. My application requires a simple square wave generator. However I need to vary the frequency , amplitude and be able to turn it on and off. I found a great instructable https://id.arduino.cc/auth/activate/xenonion/6d9f3e237166d1f00dd8cd56ed410161 that solves all the problems and have rewritten it to only include the square wave generation part.
My problem now is working with the interrupt, it of course works so well. I want to be able to start the square wave run it for a specific time period and then stop it.
A common device is to provide a volatile boolean flag to tell an interrupt routine
whether it should be doing anything at all - set it false until you need the routine
to do stuff. The fact the interrupt is running just to check the flag isn't a problem,
thats not taking many cycles.
Sometimes you don't need a flag, there are enough variables already that can
serve the purpose (say you have one to select the waveshape - one of the values
could simply mean "no wave").