The only problem remaining is that if I ground an input then move to another input without lifting off/letting go of the "button", no midi messages are sent.
Save the last value of the "val" variable in a static variable called something like "lastVal". Then when you check pin 8 to see if you need to send a note, also send it if lastVal was not equal to val.
Thanks for your suggestion Grumpy Mike, I think that should work. I was not aware of static variables, interesting. I am learning alot through this project about how to write code, tis great a great learning experience. I assume in this instance I could use a global variable to do the same job, is this correct?
PieterP, Thanks so much for your help. I just realised that you are "tttapa" the creator of the midi controller and control surface library. Thank you so much for the work you have done for the community.
I have used the midi controller library multiple times for projects, LOVE IT!
bryanfury:
PieterP, Thanks so much for your help. I just realised that you are "tttapa" the creator of the midi controller and control surface library. Thank you so much for the work you have done for the community.
I have used the midi controller library multiple times for projects, LOVE IT!
Glad to hear you found it useful!
I assume in this instance I could use a global variable to do the same job, is this correct?
Yes you could, but the use of a static variable sort of seals the variable into that function. This stops it being changed by any other function by accident.
While in a small piece of code it is not important, as code grows and especially when several people are writing bits of the code at the same time it becomes increasingly important. An example of this is say you wanted to use the variable i as an index like it so often is, then having it as a static variable means each function can have its own copy of the variable, if you want.
This is often used to make functions reusable, so you can just copy them into other code or libraries without worrying if that variable name had been used elsewhere.