I am using the analogRead from a potentiometer within the Arduino's main loop. That value is then being passed into a function that is also in the loop. What I need to do is make sure the function in question does not get invoked until the variable actually increments or decrements i.e. if the value stays on say 60, the function isnt called, but as soon as the variable changes to say 61 or 59, then the function is called. At the minute the function is firing every reiteration of the Arduino's main loop:
My code so far, but it doesn't work. I know why is doesn't work, but I can't figure out a way to do this so far.
void loop() {
val = analogRead(14);
val = map(val,0,1024,0,127);
storedVal = val;
if(!(val == storedVal)) {
usbMIDI.sendControlChange(kMidiControl, val, kMidiChannel);
}
delay(50);
}