I have been working on a small switch panel for flight sims, but I wanted to use the CYT1100 Digital Rotary encoders to move instruments in-game. I have the code set up to press a certain joystick button for each pulse. The code seems to work fine, but I might have some issues with hardware.


  • Arduino Micro
  • CYT1100 Digital Rotary Encoders
  • Acer Aspire E5 (Windows 10)

I get serial monitor outputs when I move the board, but the rotary encoders aren't plugged in. The values are around 2 to -2 but don't change depending on the encoders. The joystick buttons are getting almost randomly pressed with no certain pattern. I was wondering if anyone has had issues like this in the past or if I'm missing something.

Here's my code:

#include <Joystick.h>

#define outputA 2
#define outputB 3

int counter = 0;
int aState;
int aLastState;

void setup() {
  pinMode(2, INPUT);
  pinMode(3, INPUT);

void loop() {
  aState = digitalRead(outputA);
  if (aState != aLastState) {
    if (digitalRead(outputB) != aState) {      // Clockwise
      counter ++;
    } else {                   // Counterclockwise
      counter --;
    Serial.print("Counter:  ");
  aLastState = aState;
  • you have it partially backward ... wait for a transition in outputA in one direction only, either a rising edge or falling edge, but not both ... when transition occurs, read value of outputB and press joystick button depending on the value
    – jsotola
    Jan 23 '20 at 0:52
  • Sorry I'm sort of new to C++ but not programming in general, so I the logic. I wait for a change in outputA, and directly after, if outputB is not down, I have a falling edge and vice versa?
    – Jacob C
    Jan 23 '20 at 1:12
  • no ... the rotary encoder probably has two outputs that are 90 degrees apart ... read the state of B everytime A changes from LOW to HIGH .... A always changes in middle of B ... bristolwatch.com/ele2/img/Encoder.jpg ........ it has nothing to do with C++
    – jsotola
    Jan 23 '20 at 2:09
  • Okay thanks! I'll try that and it should fix some issues.
    – Jacob C
    Jan 23 '20 at 12:51
  • 1
    I updated the code... Does that look about right?
    – Jacob C
    Jan 23 '20 at 15:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.