Rotary Encoder as a pushbutton

Hi, I 'm developing my project keypad.

In my previous post:

http://forum.arduino.cc/index.php?topic=321771.0

I set 14 buttons , 6 axes , and now want to add the rotary encoder so that when turning left or right performs the push of a button or another.

The rotary encoder according to the will connect this diagram

I would know I have to add to my current sketch to make it work as I want.

//Quadrant 6 ejes y 14 botones
//Ejes de pin A0 a A5
//Botones desde pin 0 a 13

const int buttonPins[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13};
const int size = sizeof(buttonPins) / sizeof(int);
const int pollRate = 50;

long m = millis();

JoyState_t joySt;

void setup()
{        
        pinMode(13, OUTPUT);


	joySt.xAxis = 0;
	joySt.yAxis = 0;
	joySt.zAxis = 0;
	joySt.xRotAxis = 0;
	joySt.yRotAxis = 0;
	joySt.zRotAxis = 0;
	joySt.throttle = 0;
	joySt.rudder = 0;
	joySt.hatSw1 = 0;
	joySt.hatSw2 = 0;
	joySt.buttons = 0;

  for (int i = 0; i < size; i++)
    pinMode(buttonPins[i], INPUT_PULLUP);    

  m = millis();
}

void loop() {
  if (millis() - m > pollRate)
  {
    m = millis();
    
    joySt.buttons = 0;
    joySt.xAxis = analogRead(A0) >>2;
    joySt.yAxis = analogRead(A1) >>2;
    joySt.zAxis = analogRead (A2) >>2;
    joySt.xRotAxis = analogRead (A3) >>2;
    joySt.yRotAxis = analogRead (A4) >>2;
    joySt.throttle = analogRead (A5) >>2;
    
    for (int i = 0; i < size; i++) {
       int state = digitalRead(buttonPins[i]); 
       if (state == LOW) 
         joySt.buttons += 1 << i;
    }   
     
     delay(50);

	if (joySt.throttle > 127)
		digitalWrite(13, HIGH);
	else
		digitalWrite(13, LOW);

    Joystick.setState(&joySt);
  }
}

Other than the obvious bug of connecting to pins 2 and 3 but your code says 0 and 1, that should work.

A lot of it depends on the encoder. Many of them do a full cycle of 4 transitions for each detent (or click) on the mechanics. So if the encoder is sitting in a detent, you will always find the same pattern (one on, all off, whatever) on the encoder's output pins. Some of them do have mechanical detents for every electrical position.

This kind of encoder,

works great, be sure to add the filter circuit shown on page 2 of the datasheet.
Member jurs wrote some code that is easy to use to read them
http://forum.arduino.cc/index.php?topic=318170.0

MorganS:
Other than the obvious bug of connecting to pins 2 and 3 but your code says 0 and 1, that should work.

I have already connected the pins correctly, but when I turn to the side, there are times that records keystrokes the opposite button. My idea is that if I right turn button 1 is pressed, and if I left turn button 2 is pressed , then turning the wheel, there are times when the right button is pressed, but I also press the opposite botton .

Any ideas?

OK, I missed that bit in the first post.

You need to understand how encoders work. They don't have a left and right button. They have two switches which cycle on and off in a pattern. By identifying the pattern, you can determine if it is moving left or right.

Your code should be modified to detect the encoder pattern and then output the signals you require.

Which software you use to create this circuit design.