OK,
So I have a 10k Linear pot hooked up correctly. But, of course I don't want to send the CC unless it has changed (the pot has been moved).
Here is my lame attempt a doing that.
void setup()
{
Serial.begin(31250);
}
int CCTH=0;
int OLDCC=1;
void loop() {
// read the pot position
CCTH = analogRead(0) / 8;
if (CCTH != OLDCC)
{
Serial.println (CCTH);
}
OLDCC=CCTH;
}
It works but it seems a little clunky. Any better way to do it???
Also, every once in a while when I stop turning the pot it will kind of be stuck sending, say 100 then 101 over and over until I tweak the pot a bit. Any ideas on what that is????
Thanks,
Todd
I have the same problem as yours, although you may replace the last line into the if statement ~
for(int loope = 0;loope < 4; loope++){
readadc[loope] = analogRead(loope)/8; //reads value from pot
if(readadc[loope] != readadctemp[loope]){
MIDI_TX(176,loope,readadc[loope]); //sends cc
readadctemp[loope] = readadc[loope]; //old value
}
So it won't update the old value after you changed the pot, it might also speed up your code abit.
Although I think this problem exist since the ADC cant decide on what value it wants to be, for as example
2.5v = 511
2.51v = 512
due 10 bit resolution?
(Im using more inputs using a for loop for that, you can leave that away if you only using one.)
Also, not trying to hijacking your topic... but do you experience glitches when sending cc or notes to your midi device?
It appears at mines that theres alot of garbage sended along with the CC messages, such as "System reset" (FF) random notes. or random hex stuff ~.
This by using MIDI OX on a windows PC and a usb midi cable. (brandless) The cable works fine on normal midi devices, except the arduino.
every once in a while when I stop turning the pot it will kind of be stuck sending, say 100 then 101 over and over until I tweak the pot a bit. Any ideas on what that is????
Yes it is the normal one bit uncertainty of any A/D converter. The input voltage is in such a state that the small amount of noise is enough to trigger a change in one in the reading. All A/D's do this and there is nothing you can do to stop it.
What you have to do is to take the difference between your current reading and the last reading and if this is greater than 2 (or more) send your MIDI. Use the ABS() function to ensure you account for positive and negative differences. There is no need to average a lot of readings.