Hello everybody
I am using a rotary encoder ( http://www.ebay.es/itm/172178149195 )
And i have some questions for my sketch (I use Joystick button usb - USB TYPE Serial/Keyb/Mouse/Joystick).
I would like that each clockwise turn, activate the button 5, and each counterclockwise, button 6.
But not always works.
Which would be better way?
Thanks in advance.
I am using a rotary encoder ( http://www.ebay.es/itm/172178149195 )
And i have some questions for my sketch (I use Joystick button usb - USB TYPE Serial/Keyb/Mouse/Joystick).
I would like that each clockwise turn, activate the button 5, and each counterclockwise, button 6.
But not always works.
Which would be better way?
Thanks in advance.
Code:
#include <Encoder.h>
void setup() {
Serial.begin(9600);
}
long oldPosition = -999;
void loop() {
long newPosition = myEnc.read();
if (newPosition != oldPosition) {
if( newPosition % 4 == 0) { //for each 4 positions of encoder)
if (newPosition > oldPosition){
Serial.print(newPosition);
Serial.println(" - Left");
Joystick.Button(5,1);
Joystick.Button(6,0);
}
else {
Serial.print(newPosition);
Serial.println(" - Right");
Joystick.Button(5,0);
Joystick.Button(6,1);
}
}
oldPosition = newPosition;
} else { //encoder same position
Joystick.Button(5,0);
Joystick.Button(6,0);
}
Joystick.send_now();
delay(4);
}
Last edited: