Go Down

Topic: if (cc != oldValue[i]) help needed *SOLVED* (Read 500 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
  }
}

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: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

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'.

Go Up