-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Push button support for Multiplexed encoders #31
Comments
Actually there is support for push buttons. See e.g. (line 15): EncoderTool/src/Multiplexed/EncPlex74165.h Lines 11 to 23 in decf3e7
Which mulitplexing scheme are you aiming for? |
I'm using the 4051, I did not look into the other multiplexer codes. |
In case you add the push button (which should be simple) to the 4051 example I'd be happy to update it.
Thanks! Let me know if you need any help or "decission support" :-) |
Hi, I can see that the schematics for the 74165 mux has a extra chip for the push buttons, |
Looking inside src, it looks like you only need to add an extra argument to the https://github.com/luni64/EncoderTool/blob/master/src/Multiplexed/EncPlex74165.h
So you give the QH pin of the third encoder (pushButtons) as Then you could use set the callbacks with it is also supposed to be analogous to lines 41 and 41 of the 74165 Multiplexed example:
I might guess it turns into:
I'll test it soon |
@hakonbraga
|
Could really use this in the 4051 portion of this library... :-) |
I can take a look at it over the weekend—it shouldn't be too difficult. However, I’d appreciate it if you could thoroughly test it, as I don’t have much time for testing right now. |
I can certainly test it as I'm in the middle of designing a device that requires it. :-) |
Oh, since you didn't respond I thought you are not interested anymore. I'll try to come up with a solution the next days. |
Sorry, the holidays had me away from my projects for a while. Thanks for taking a look. |
I uploaded an experimental version to the branch "AddMultiplexedButton_4051". I currently can't test it, so I hope it works. At least it compiles :-) Here some test code (also untested). It uses three 4051 sharing the same address pins S0..S2. Two of the chips handle the phases A/B and the third handles the buttons. #include "EncoderTool.h"
using namespace EncoderTool;
constexpr unsigned encoderCount = 8; // number of attached encoders
constexpr unsigned S0 = 0; // address pin 0
constexpr unsigned S1 = 1; //...
constexpr unsigned S2 = 2; // address pin 2
constexpr unsigned SIG_A = 3; // output pin SIG of multiplexer phase A
constexpr unsigned SIG_B = 4; // output pin SIG of multiplexer phase B
constexpr unsigned SIG_BTN = 5; // output pin SIG of multiplexer button
// breakout: https://www.sparkfun.com/products/13906
// datasheet: https://www.ti.com/lit/gpn/CD74HC4051
EncPlex4051 encoders(encoderCount, S0, S1, S2, SIG_A, SIG_B, SIG_BTN);
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
encoders.begin();
}
unsigned t0 = 0;
void loop()
{
encoders.tick();
for (unsigned i = 0; i < encoderCount; i++)
{
if(encoders[i].valueChanged())
Serial.printf("E%d: %d\n", i, encoders[i].getValue());
if(encoders[i].buttonChanged())
Serial.printf("B%d: %d\n", i, encoders[i].getButton());;
}
} Please let me know if it works |
You are correct, it compiles. Now I just need to figure out if it works with callbacks for buttons. :-) |
If you want to attach different callbacks for the various buttons you can use #include "EncoderTool.h"
using namespace EncoderTool;
constexpr unsigned encoderCount = 8; // number of attached encoders
constexpr unsigned S0 = 0; // address pin 0
constexpr unsigned S1 = 1; //...
constexpr unsigned S2 = 2; // address pin 2
constexpr unsigned SIG_A = 3; // output pin SIG of multiplexer phase A
constexpr unsigned SIG_B = 4; // output pin SIG of multiplexer phase B
constexpr unsigned SIG_BTN = 5; // output pin SIG of multiplexer button
// breakout: https://www.sparkfun.com/products/13906
// datasheet: https://www.ti.com/lit/gpn/CD74HC4051
EncPlex4051 encoders(encoderCount, S0, S1, S2, SIG_A, SIG_B, SIG_BTN);
void callback(int encNr, int state) // will be called for each button
{
Serial.printf("Button: %d, State: %d", encNr, state);
}
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
for (unsigned i = 0; i < encoderCount; i++)
{
encoders[i].attachButtonCallback([i](int state) { callback(i, state); });
}
encoders.begin();
}
void loop()
{
encoders.tick();
}
|
Well, it compiles. So, step one is good! :-) |
Just tested it on real hardware and it is working well. Didn't need to debounce the presses either, which I was concerned might be an issue. I made an individual callback for each of eight encoder buttons and it all worked swimmingly well. Thanks so much!!! |
Great! PS: the buttons are debounced internally (I'm using the bounce2 lib from Thomas Frederic https://github.com/thomasfredericks/Bounce2) |
Am I correct to assume their is no push button support for Multiplexed encoders?
Is it in the pipeline?
The text was updated successfully, but these errors were encountered: