Encoder with clickinterval

Status
Not open for further replies.

757

Active member
Hello, I am trying to get this program to work using Clickinterval, so when I spin the encoder faster it changes the dataref in X Plane faster.
I can get the encoder to work perfectly but I can't get it to spin faster when I turn the encoder faster. Turning it slow is fine. Here is my program if anyone who is familiar with this help me out?



#include <Encoder.h>

Encoder IasEncoder = Encoder(1,2);

int countIas = 0;
int IasEncoder_prev = 0;
int IasEncoderVal = 0;

FlightSimCommand IasUP;
FlightSimCommand IasDN;


elapsedMillis IASEncoderClickInterval = 0;




void setup() {
// put your setup code here, to run once:

pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);


IasUP = XPlaneRef("1-sim/comm/AP/spdUP");
IasDN = XPlaneRef("1-sim/comm/AP/spdDN");




}

void loop() {

FlightSim.update();





long IasEnc = IasEncoder.read();
if (IasEnc != IasEncoder_prev){
IasEncoderVal = (IasEnc - IasEncoder_prev);
if(IasEncoderVal == -1){
countIas++;
}
if(IasEncoderVal ==1){
countIas--;
}
IasEncoder_prev = IasEnc;

if(countIas==2){
IasDN.once();
countIas = 0;
}

if(countIas ==-2){
IasUP.once();
countIas = 0;
}

if(IASEncoderClickInterval > 30){
IasEncoderVal = IasEnc * .25;
}else{
IasEncoderVal = IasEnc * 5.0;
IASEncoderClickInterval = 0;
}

}

}
 
Status
Not open for further replies.
Back
Top