Pages: [1]   Go Down
Author Topic: if (cc != oldValue[i]) help needed *SOLVED*  (Read 452 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley
« Last Edit: February 06, 2013, 10:15:59 am by raviolifaceman » Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 70
Posts: 2174
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe this can be of some help:

Code:
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
  }
}
Logged


Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 208
Posts: 8860
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, that's perfect and it solved the problem perfectly smiley
Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 70
Posts: 2174
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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'.
Logged


Pages: [1]   Go Up
Jump to: