Go Down

Topic: if (cc != oldValue[i]) help needed *SOLVED* (Read 641 times) previous topic - next topic

raviolifaceman

Feb 06, 2013, 03:56 pm Last Edit: Feb 06, 2013, 04:15 pm by raviolifaceman Reason: 1
Hey!
I'm putting together my first MIDI controller in Arduino and the CC it's sending out is a little too unmanaged. I want to take "if (cc != oldValue" and change it a little to mean this:

If the new CC is different to but at least 3 away from the old value, send the CC.

Thanks to anyone that can help :)

pYro_65

Maybe this can be of some help:

Code: [Select]

void DoCC( int new_CC ){

  static int prev_CC = 0;

  if( new_CC >= ( prev_CC + 3 ) || new_CC <= ( prev_CC - 3 ) ){
   
    prev_CC = new_CC;
    //Send CC
  }
}
Forum Mod anyone?
https://arduino.land/Moduino/

johnwasser


If the new CC is different to but at least 3 away from the old value, send the CC.


Code: [Select]

const int deadZone = 3;
if ((newValue+deadzone) < oldValue || newValue > (oldValue+deadZone)) {
}

Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

raviolifaceman

Thanks, that's perfect and it solved the problem perfectly :)

pYro_65



If the new CC is different to but at least 3 away from the old value, send the CC.


Code: [Select]

const int deadZone = 3;
if ((newValue+deadzone) < oldValue || newValue > (oldValue+deadZone)) {
}




The deadZone needs to be 2 otherwise the 'at least 3 away' becomes 'at least 4 away'.
Forum Mod anyone?
https://arduino.land/Moduino/

Go Up