Hi, sorry here is the code I use now:
Code:
#include <Bounce.h>
#include <Encoder.h>
/* declare 'gamepad' around here please :) */
Bounce button2 = Bounce(1, 10);
Bounce button3 = Bounce(2, 10);
long oldPosition = 0;
Encoder myEnc(0, 1);
int8_t dir=0,odir=0;
uint8_t isChanged=0;
void setup() {
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
//Serial.begin(Serial.baud());
}
void loop() {
button2.update();
button3.update();
long newPosition = myEnc.read()/2;
dir=newPosition-oldPosition;
oldPosition=newPosition;
if(dir>0) {
Gamepad.button(2, 1);
isChanged=1;
} else if(dir<0) {
Gamepad.button(3, 1);
isChanged=1;
} else if(odir>0) {
Gamepad.button(2, 0);
isChanged=1;
} else if(odir<0) {
Gamepad.button(3, 0);
isChanged=1;
}
odir=dir;
if (button2.fallingEdge()) {
Gamepad.button(2, 1);
isChanged=1;
}
if (button3.fallingEdge()) {
Gamepad.button(3, 1);
isChanged=1;
}
if (button2.risingEdge()) {
Gamepad.button(2, 0);
isChanged=1;
}
if (button3.risingEdge()) {
Gamepad.button(3, 0);
isChanged=1;
}
if(isChanged) {
Gamepad.send_now();
isChanged=0;
}
}