Last class, I learned how to play tone with tone() function in Arduino. Tom mentioned that we could basic idea about loop if we can make pause(or stop) and replay procedures to work within the loop.

Let us take a look at example code.

Somethings we need to deal with it are:

1. We don’t need for because for is a loop. But, we need several global variables to track statue in the loop.
2. For pause procedure, we simply use reserve word return.
3. For replay procedure, we will reset some global variables to their default value, then return.
4. I am trying to play the song longer.

Here is the modified code.


Final Result.