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);
}
}