Go Down

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

#### raviolifaceman

##### Feb 06, 2013, 03:56 pmLast 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

#1
##### Feb 06, 2013, 04:05 pm
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

#2
##### Feb 06, 2013, 04:07 pm

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
See who has no social life: https://forum.arduino.cc/index.php?action=stats

#### raviolifaceman

#3
##### Feb 06, 2013, 04:15 pm
Thanks, that's perfect and it solved the problem perfectly

#### pYro_65

#4
##### Feb 06, 2013, 04:20 pm

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