Hello everyone,
So, im currently trying to make a button box to work with X-Plane11, and, in order to get familiarezed with arduino, wiring and coding the components i've been doing little sections of it to better understand how things work (since i am a beginner at all this) and then put all these little parts togheter.
This time i tried to make a single rotary encoder to interface with the SIM, but it did not work as i expected, the pushbutton function worked just fine, as well as the counter clockwise rotation, however, the clockwise rotation was really bad.
Basically, when i turn the knob clockwise either nothing happens, or it sees it as a counter clockwise rotation.
can anyone help me figure out what is going on, please?
Here is the code that i made:
#include <Joystick.h>
Joystick_ Painel(JOYSTICK_DEFAULT_REPORT_ID,
JOYSTICK_TYPE_JOYSTICK,
3,
false, // y axis
false, // x axis
false, // z axis
false, // rx axis
false, // ry axis
false, // rz axis
false, // rudder
false, // throttle
false, // accelerator
false, // brake
false); // steering wheel
#define CLK 9
#define DT 8
#define SW 7
int currentStateCLK;
int previousStateCLK;
void setup() {
pinMode(CLK, INPUT);
pinMode(DT, INPUT);
pinMode(SW, INPUT_PULLUP);
previousStateCLK = digitalRead(CLK);
Painel.begin();
}
void loop() {
Check_Rotation();
Check_Push();
}
void Check_Rotation(){
currentStateCLK = digitalRead(CLK);
if(currentStateCLK != previousStateCLK){
if(digitalRead(DT) != currentStateCLK){
Painel.setButton(1,1);
delay(50);
Painel.setButton(1,0);
}else{
Painel.setButton(0,1);
delay(50);
Painel.setButton(0,0);
}
previousStateCLK = currentStateCLK;
}
}
void Check_Push(){
if (digitalRead(SW) == LOW){
Painel.setButton(2, 1);
}else{
Painel.setButton(2,0);
}
}