I'm trying to get it to work with the example code provided by Sparkfun-- replacing delay() with mills(), except it doesn't work the same. Where am I going wrong?
Here:-
replacing delay() with mills(),
You can not do that. It is not a direct replacement it is a conceptual replacement. All you are doing in your code is making a section of code behave EXACTLY like delay with all the things wrong with it. In fact it is very close to how delay is actually defined.
As mentioned many times you need to structure your code to look and see if it is time to do something, if so do it if not look to see if is the time to do something else.
You have only two things to do, turn on a note or turn off a note so there are only two if statements in your loop.
- Is it time to produce a note - that is has a button been pressed to start one? - if so send note on message.
- Is it time to stop your note - that is has enough time elapsed since the note started - if so send the note off message.
I see no evidence of you trying to do that in your code.