I'm using leonardo board
i want if encoder turn counterclockwise then press any keyboard button
and if encoder turn clockwise then press another keyboard button
and if encoder don'move release those keys
but i check my encoder, there is no error but if i turn the encoder more than 4 or lots then keep press button until shut off the arduino is ther any problem in my code?
#include <Encoder.h>
#include<Keyboard.h>
typedef struct{
byte KeyL;
byte KeyR;
long Old;
long Now;
int Wait;
int Current;
} ENCODER;
void EncoderRead(ENCODER* Enc);
void EncoderRead(ENCODER* Enc){
if ((Enc->Old != Enc->Now)) {
Enc->Current = millis();
if (Enc->Old < Enc->Now) {
Keyboard.press(Enc->KeyR);
}else{
Keyboard.press(Enc->KeyL);
}
}else if((int)(Enc->Current+Enc->Wait) <= millis()){
Keyboard.release(Enc->KeyL);
Keyboard.release(Enc->KeyR);
}
Enc->Old = Enc->Now;
}
ENCODER NovA ={0,0,0,0,0,0};
Encoder NovA_Pin(10,11);
void setup() {
NovA.Wait = 12;
//키 값 정의(아스키코드 기준)
NovA.KeyL = 'j';
NovA.KeyR = 'k';
Keyboard.begin();
Serial.begin(9600);
}
void loop() {
NovA.Now = NovA_Pin.read();
EncoderRead(&NovA);
}