rotary encoder to keyboard error
i'm using leonardo board
i want if encoder turn counterclockwise press keyboard button
and if encoder turn clockwise press keyboard button
and if encoder don'move release keys
but check encoder, there no error if turn encoder more 4 or lots keep press button until shut off arduino ther problem in 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);
}
i want if encoder turn counterclockwise press keyboard button
and if encoder turn clockwise press keyboard button
and if encoder don'move release keys
but check encoder, there no error if turn encoder more 4 or lots keep press button until shut off arduino ther problem in 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);
}
hi,
welcome forum.
please read first post in forum entitled how use forum.
http://forum.arduino.cc/index.php/topic,148850.0.html down item #7 how post code.
it formatted in scrolling window makes easier read.
thanks.. tom..
welcome forum.
please read first post in forum entitled how use forum.
http://forum.arduino.cc/index.php/topic,148850.0.html down item #7 how post code.
it formatted in scrolling window makes easier read.
thanks.. tom..
Arduino Forum > Using Arduino > Programming Questions > rotary encoder to keyboard error
arduino
Comments
Post a Comment