Knob encoder velocity multiplier qestion

Status
Not open for further replies.

MatrixRat

Well-known member
Working an a usbMidi master clock project which currently provides eight separate Midi clock sources and is controllable via the usual transport commands and some device-specific CC messages and it's time for some user interface hardware.

Starting with encoders, testing on a T3.6 and using Bourns R/C debounce circuit and non-detent, 96ppr encoder, here's relevant code currently in use. IDE 1.8.12 TD 1.51.

Code:
#include <Encoder.h>
Encoder encoder1(2, 3);
int previousEncoderInterval;
int encoderInterval = 500;// polling every 500 uSec ..
int encoder1Min= 0;
int encoder1Max= 1023;
int encoder1InitialValue = 120;
int encoder1Lag; 
int encoder1Value;
int  tempo1;
//**********************************************************
void setup() 
{
  delay(1000);           
  Serial.begin(115200);
  encoder1.write(encoder1InitialValue);
}
//**********************************************************
void loop()
{
   unsigned long currentEncoderTime = micros();
      if(currentEncoderTime - previousEncoderInterval > encoderInterval)
        {
        previousEncoderInterval = currentEncoderTime;  
          {
          long encoder1Value = (encoder1.read());
            if(encoder1Value>encoder1Max)
            {
            encoder1Value=encoder1Max;encoder1.write((encoder1Value));
            }
            else if(encoder1Value< encoder1Min)
              {
              encoder1Value=encoder1Min;encoder1.write((encoder1Value));
              }
              else if (encoder1Value != encoder1Lag) 
                {
                encoder1Lag = encoder1Value;
                tempo1=(encoder1Value);
                    Serial.print("Encoder 1 ");
                    Serial.println(tempo1,DEC);
                }
           }
      }
}
Which works but needs a motor on it. Ok thats a big value for tempo but with an eye on a future project which will be looking at 0 - 16383 I'm seeking guidance as to how to implement a rotational velocity sensitive value multiplier.

Been spoiled by this native feature of Behringer BCR-2000's encoders. The user does not have control of velocity thresholds but can assign multiplier values to each of four. Once you get used to it, its easy not to want to use pots any more.

Thanks for reading and hands up from back of junior class anyone?
 
I'm seeking guidance as to how to implement a rotational velocity sensitive value multiplier.

Thanks for reading and hands up from back of junior class anyone?

You're halfway there, since you are already saving the previous encoder value as Encoder1Lag.
Take the difference of Encoder1Value and Encoder1Lag. That delta will give you a velocity estimate; you might need to slow down polling to get better resolution. Then, if you want behringer-like steps, use that delta to choose an increment value (e.g. if delta < 2, increment by 1; if delta >2, increment by 10, etc.). Or, compute an increment using a power function of the delta, or sumthin' tricky. Add the increment value to the Encoder1Value, save that back to the Encoder1Value as well as the Lag, for next time, and update the tempo variable.
 
Thank you for those tips. I get it that the polling rate needs to be slowed to let bigger values through theoretically giving some range of values related to rotation speed.

Realized some time after starting this thread that the encoder1Value encoder1Lag relationship is one to exploit and was mulling over looking at picking out the time between single value changes. Either way, looks like a good first starting point to get working. Will report back.
All the best.
 
Status
Not open for further replies.
Back
Top