Giter Club home page Giter Club logo

encoder's People

Contributors

john-lluch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

encoder's Issues

small extra feature?

I am happy to find what I went looking for, namely the rotary encoder done on a general timer interrupt.

I didn't see that the pushbutton enjoyed the same "attention", that is to say pressing and releasing it can be missed.

I was able to modify your code to set a flag when the button goes down. I added a wentDown function and also provided a clear Flag function. With

//***
  bool wentDown() { return downFlag; }
  void clearFlag()  { downFlag = false; }

and

  if (pDebouncer.isDebounced( pb, DEBOUNCE_COUNT) && _encoderButtonVL != pb) {
    _encoderButtonVL = pb ;

//***
    if (pb != lastPB) {
    	if (pb)
    		downFlag = true;
      lastPB = pb;
    }
  }

which could also have similar flag/reset for button going up... but I am not a C++ programmer, I've never been good at naming things and for all I know the code already provides a way to do this so...

I write here in case you'd like to add something along these lines to your object.

I'm OK with my modifications to your object and will use it. Very well done right, THX!

a7

Nano: button works, but noise on rotary

Thanks for the great library (no problems compiling on the nano btw!)

Unfortunately, I'm having trouble getting it to work right on my project. The button functionality works no problem, but the rotary delta seems to be mostly 0s with a few 1, -1, 256, -255, etc that doesn't react to my turning the wheel.

I've tried now two separate arduinos (a nano and a mega) and two separate REs and wirings (one in my project, and a second isolated with only the RE in play and nothing else connected).

Even running stripped down code based on your model code, I can't seem to get it to work: https://github.com/brianssparetime/darkroom_timer/blob/main/rotary_encoder_test/rotary_encoder_test.ino

In terms of hardware, I have one of the button pins and the middle pin of the RE tied to ground, and the remaining pins going directly to the digital inputs, as shown at the top of the code above.

I'm at a loss for what I'm doing wrong. Any help would be appreciated.

Hold?

How to call for hold (long press) > action ?

Adding a ready to compile example-code?

Hi John,

I was looking at the example-code in the comment-section of the encoder.h

/* USAGE FOR ONE ENCODER:
// define the input pins
#define pinA 19
#define pinB 20
#define pinP 21
// create an encoder object initialized with their pins
Encoder encoder( pinA, pinB, pinP );
// setup code
void setup() 
{
  // start the encoder time interrupts
  EncoderInterrupt.begin( &encoder );
}
// loop code
void loop()
{
  // read the debounced value of the encoder button
  bool pb = encoder.button();
  // get the encoder variation since our last check, it can be positive or negative, or zero if the encoder didn't move
  // only call this once per loop cicle, or at any time you want to know any incremental change
  int delta = encoder.delta();
  // add the delta value to the variable we are controlling
  myEncoderControlledVariable += delta;
  // do stuff with the updated value
  // that's it
}
*/  
´´´
it is missing the include-compiler-directive
Would you mind adding this to make the code ready to compile?

best regards Stefan 

Please add a License

Hello,
Thank you for this code. Can you please add a License. Without a license it is impossible to use it legally. MIT, BSD or Apache would be great.

ATMega328 not supported?

See below for errors I get.

I'm pretty sure that these problems are because I'm trying to use it on an Arduino Nano.
However, I'm not 100% sure as I still get other errors when compiling for Arduino Mega. Does it also require another timer library to be included?

Anyway, it would be nice to have something in the Readme about what board it requires and maybe a complete example with includes.

......

Arduino: 1.8.9 (Mac OS X), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

Build options changed, rebuilding all
sketch/Encoder.cpp: In function 'void setupTimerInterrupt()':
Encoder.cpp:12:3: error: 'TCCR3A' was not declared in this scope
TCCR3A = 0; // set entire TCCR3A register to 0
^
Encoder.cpp:13:3: error: 'TCCR3B' was not declared in this scope
TCCR3B = 0; // same for TCCR3B
^
Encoder.cpp:14:3: error: 'TCNT3' was not declared in this scope
TCNT3 = 0; //initialize counter value to 0
^
Encoder.cpp:17:3: error: 'OCR3AH' was not declared in this scope
OCR3AH = 0;
^
Encoder.cpp:23:3: error: 'OCR3AL' was not declared in this scope
OCR3AL = INTERRUPT_PERIOD;
^
Encoder.cpp:26:3: error: 'TIMSK3' was not declared in this scope
TIMSK3 = (1 << OCIE3A);
^
Encoder.cpp:26:18: error: 'OCIE3A' was not declared in this scope
TIMSK3 = (1 << OCIE3A);
^
Encoder.cpp:29:19: error: 'WGM32' was not declared in this scope
TCCR3B |= (1 << WGM32);
^
Encoder.cpp:32:19: error: 'CS30' was not declared in this scope
TCCR3B |= (1 << CS30) | (1 << CS31);
^
Encoder.cpp:32:33: error: 'CS31' was not declared in this scope
TCCR3B |= (1 << CS30) | (1 << CS31);
^
exit status 1
'TCCR3A' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Using encoders without pushbutton?

Hey John!

Is it possible to use this library with encoders that don't have pushbuttons? Or if I have encoders that have pushbuttons but don't want to use them in my project, is there any way I can utilize your wonderful library while leaving the pushbutton pins not connected to the board?

It looks like no matter what I need to pass three variables for pin locations in while creating a new Encoder object, so I'm assuming if I just pass in the pins A and B then that won't work...is there perhaps any way I can pass in a null value for the pushbutton pin and still get everything to compile?

The reason I'm not connecting push buttons is to save digital pin space...I've got an Arduino Micro and I'm trying to hook up 5 encoders along with some other switches so all of my digital pins are basically taken up. I may be able to move the switches onto some analog pins and make that work but still, if I can use your library and get away without the pushbuttons I'd love that!

I've tried several other encoder library solutions and none seem to be giving me the result I need so I'd like to give yours a go!

I'm still pretty fresh with Arduino programming so forgive me if this is an easy issue to solve.

Thanks!
Stan

Bob

Hello John,
First, Encoder.h is brilliant!, but I have an issue.

I have 9 encoders in my project. I have tested all encoders one by one, they all work correctly with Encoder.h.
I can take any 4 of the encoders in any order (i.e. 1,2,3 & 4 | 3,5,7 & 9 | 1.5.7 & 9) and they work as expected!

However as soon as I increase the number of encoders in the Array to 5 or more, (it compiles OK) but goes into the void loop and never gets out - its a show stopper.

I am reluctant to submit this but I am never going to correct this issue by myself and it may benefit other people.

Thank You
Bob Telfer

ESP32

Hi John-Lluch,
This looks exactly what I need and I will give it a try. I have tried one or two other Encoder libraries and they have given problems. I am using an ESP32 running the Arduino core. I will let you know how it goes but if you are aware of any potential problems I'd be grateful if you could let me know in advance.

Many thanks for all your work.

using the millis() timer0 alternative

Any sense I made of using the millis() compare A and B mechanism seemed to need an additional ISR, in fact it did not work until I added the following nearly identical function in the section marked "/* Alternative using timer 0 that is used for millis()":

SIGNAL(TIMER0_COMPB_vect) 
{  
  computeEncoder();
}

I write in case that was your intent and it got dropped somewhere in an editing mistake. With both ISRs it seems like I am getting 2000 Hz attention to the pins, but I have not verified this yet until I figure out how. To.

a7

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.