Hello!
I am new to arduino and very new to programming. I do, however, have some electronics and electrical troubleshooting skills.
Ok, so I am trying to use this rotary encoder library, which I found in the arduino playground:
I am using this encoder:
I am having two problems.
1: The encoder has 12 detents, but the program keeps moving through 24 positions on the lcd. If I go between detents, I can access the "in-between" positions, but I would like 1 detent to count as 1 position.
2: I cannot get the pushbutton "clicker" to work.
Here is what I have tried:
1: I read in the "readme" this:
Depending on the type of your encoder, you can define use the constructors parameter stepsPerNotch an set it to either 1, 2 or 4 steps per notch, with 1 being the default.
If you have trouble with certain encoders, try
#define ENC_DECODER (1 << 2)
to use a table-based decoder, which can then be tuned using
#define ENC_HALFSTEP
The default is ENC_HALFSTEP 1.
I have tried changing both the "stepsPerNotch" and "ENC_HALFSTEP" values in the "ClickEncoder.h" text. Then I save and re-upload to the arduino, but it has absolutely no affect what-so-ever. Just as a sanity check, I removed the last curly brace in ClickEncoder.h and then when I tried to upload I received an error. This told me that I am editing the right program.
Here is the section of code I was trying to alter. Do I need to do something other than merely changing said values?:
// ----------------------------------------------------------------------------
#define ENC_NORMAL (1 << 1) // use Peter Danneger's decoder
#define ENC_FLAKY (1 << 2) // use Table-based decoder
// ----------------------------------------------------------------------------
#ifndef ENC_DECODER
# define ENC_DECODER ENC_NORMAL
#endif
#if ENC_DECODER == ENC_FLAKY
# ifndef ENC_HALFSTEP
# define ENC_HALFSTEP 1 // use table for half step per default
# endif
#endif
// ----------------------------------------------------------------------------
class ClickEncoder
{
public:
typedef enum Button_e {
Open = 0,
Closed,
Pressed,
Held,
Released,
Clicked,
DoubleClicked
} Button;
public:
ClickEncoder(uint8_t A, uint8_t B, uint8_t BTN = -1,
uint8_t stepsPerNotch = 1, bool active = LOW);
And 2:
As for the "clicker" button, I have tried using every pin combination I can think of based on what I am seeing here:
// encoder
ClickEncoder Encoder(A0, A1, A2, 2);
void timerIsr(void) {
Encoder.service();
}
// ----------------------------------------------------------------------------
I know that the encoder inputs are A0 and A1, because that is what works. I have tried using A2 and 2 as clicker inputs with the other leg going to both 5v and 0v, but no combination has worked.
I have been trying to get this to work for hours. I try to read the code, but I only understand a very limited amount. Please help!
I have tried to find what all the inputs for "ClickEncoder Encoder(A0, A1, A2, 2);" but I cant find any reference in the sketch or the .h. Also, why 4 inputs? The encoder should only need 2, plus one for the momentary, correct?
I currently have terminals A and B from the encoder going to A0 and A1, and terminal C going to 0v. This is working. Then, as I have just explained, I have tried every other combination I can think of with the remaining pins/terminals.
I tried posting the rest of the code here, but i guess there's a character limit that gets exceeded. If you need to see it I can post it in a reply.
Thanks for any help!