Need guidance on getting rotary encoders to work for my flight sim panel

I am very close to solving this :wink:

I've decided to use another code just to focus on the rotary encoder. This new code now uses a library which, in my opinion, made the reading of the encoder rotations a LOT better.

After trying to understand the coding language, I was able to add the necessary codes to set the effects when the dial is turned CW and CCW. What I did was this: when the user turns the knob clockwise, say, twice, it will print a message saying the movement was clockwise, and also displays the value.. like this "Clockwise turn - new value 2". Then, I added a code so that it will press a joystick button corresponding to the clockwise pin on the micro controller (joystick.button)

My new problem is that.. once pressed, it remains pressed unless I turn the knob to a different direction (CCW, in the example). I'd like for the button to release after one press, then start from scratch again.

Here is the new code:

#include <Encoder.h>

// Change these two numbers to the pins connected to your encoder.
// Best Performance: both pins have interrupt capability
// Good Performance: only the first pin has interrupt capability
// Low Performance: neither pin has interrupt capability
Encoder myEnc(10, 11);
// avoid using pins with LEDs attached

void setup() {
Serial.begin(9600);
Joystick.useManualSend(true);
}

long oldPosition = 0;

void loop() {
long newPosition = myEnc.read();
if (newPosition != oldPosition) { // there was a rotation

    if (newPosition > oldPosition) {    // rotation is clockwise
    Serial.print("Heading Direction: ");
    Serial.print("Clockwise");
    Serial.print(" -- Value: ");
    Serial.println(newPosition);
    Joystick.button(10+1, 1);
    Joystick.button(11+1, 0);
    Joystick.send_now();
       
    } else {                            // rotation is counter-clockwise
    Serial.print("Heading Direction: ");
    Serial.print("Counter-clockwise");
    Serial.print(" -- Value: ");
    Serial.println(newPosition);
    Joystick.button(11+1, 1);
    Joystick.button(10+1, 0);
    Joystick.send_now();
    
    }

oldPosition = newPosition;

}

}