简体   繁体   中英

How to use rotary encoder like a button for Arduino Uno

First sorry for my bad english and I hope u understand what I mean

I want make something with arduino Uno that makes a pwm signal with 50% duty cycle and variable frequency between 10 hz and 2Khz on pin 13

I want to set the frequency with an rotary encoder in such way that when I rotate the encoder one step to left, it likes up button pressed and when I rotate it one step to right it likes down button pressed

I don't want there is a counter, when I rotate to left counter+1 and when I rotate to right counter-1

I don't want the location of encoder between -infinite to 0 to +infinite

I want it do like two buttons

I hope u understand what I want

With Encoder library by Paul Stoffregen available in Library Manager, you can reset the count with encoder.write(0) .

  int direction = encoder.read();
  if (abs(direction) >= ENCODER_PULSES_PER_STEP) {
    if (direction > 0) {
      // do something for step up
    } else {
      // do something for step down
    }
    encoder.write(0);
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM