Rotary encoder reading


hi all,

first of all,

i tried searching on internet find answer problem due lack of experience cannot find understanding me...

in midi usb project make midi controller want use rotary encoders.

i use encoder.h lib pjrc website. easy lib use , able readings on serial monitor.

i have 2 questions:

1. want limit values between 0 , 127 did following code:

code: [select]
#include <encoder.h>

// change these 2 numbers pins connected encoder.
//   best performance: both pins have interrupt capability
//   good performance: first pin has interrupt capability
//   low performance:  neither pin has interrupt capability
encoder myenc(38, 40);
//   avoid using pins leds attached

void setup() {
  serial.begin(9600);
  serial.println("basic encoder test:");
}

long oldposition  = -999;

void loop() {
  long newposition = myenc.read();

    if(newposition > 127){
      newposition = 127;
    }
   
    if(newposition < 0) {
       newposition = 0;
    }
       
  if (newposition != oldposition) {
   
    oldposition = newposition;
    serial.println(newposition);
   
  }


}


so upper , lower value limited. example go "10 clicks" below 0 have turn first "10 clicks" before counting starts again. eliminate that.

2.
this encoder gives 4 readings per "click" (i hope correct). each "click" 4 readins in searial monitor. how can program send reading when encoder makes "click"

thanks in advance , excuse me bad grammar.

regards

jazzy

encoder.h not know variable "new position" in code.

the library command reset encoder value ::write(value). in case encoder myenc

code: [select]
if(newposition > 127){
      newposition = 127;
      myenc.write(127);
    }
   
    if(newposition < 0) {
       newposition = 0;
       myenc.write(0);
    }


quote
how can program send reading when encoder makes "click"
divide 4


Arduino Forum > Using Arduino > Programming Questions > Rotary encoder reading


arduino

Comments

Popular posts from this blog

DHT11 Time out error using v0.4.1library

Sketch upload fails with Java error (___REMOVE___/bin/avrdude)!

Arduino Uno + KTY81/210 temperature sensor