Three Buttons Into Two

I have a hilt in for a little bit of work and reprogamming. Unusually it has three buttons, but the idea is two of those are the POWER button and one is the AUX. However it looks as though the switches have been wired to all three button pads.

This doesn’t come up often, and I’d prefer not to rewire if I can help it, so can I just check that if I want two buttons to be POWER and one to be AUX, is this the kind of button array I need:

#ifdef CONFIG_BUTTONS
Button PowerButton(BUTTON_POWER, powerButtonPin, "pow");
Button PowerButton(BUTTON_POWER, aux2Pin, "pow");
Button AuxButton(BUTTON_AUX, auxPin, "aux");
#endif

Thanks in advance.
:slight_smile:

I’m not sure if the names (in quotes) being the same is problematic (I would think not, I can’t come up with a reason off the top of my head), but otherwise that’s pretty much exactly what I’d expect, yep.

You do need to change one of the PowerButton to something like PowerButton2, since multiple objects can’t have the same name in c++

But I need both buttons to basically BE the POWER button. It will be two-button operation to the user, but with a choice f two POWER buttons. Really those two buttons should have been paralleled, but it seems like they haven’t been in this case. (Though I’ve not got round to getting a meter on things yet).

Why not just move the wire at the board over to the same pad?

Yeh, I might have to.
I just figured one line in a config would be easier, but it’s looking like that might not be an option. :confused:

Changing the name of the object has no impact on it’s function.
You could name them Hewey, Dewey and Luiy and it would still work fine.

Once you rename one of the objects to PowerButton2, this should work well and do what you want.
There is a slight caveat that pushing both power buttons at the same time may potentially confuse something as you get press-press-release-release events, but I’m not sure if anything would notice that or not.

3 Likes

And the “pow”, “pow” and “aux”, that is just for serial monitor, so you could name them “pow”, “pow2” & “aux” to make some possible future troubleshooting easier.

Ahh, fantastic. Thanks Prof. :pray:
So something like this should do it:

#ifdef CONFIG_BUTTONS
Button PowerButton(BUTTON_POWER, powerButtonPin, "pow");
Button PowerButton2(BUTTON_POWER, aux2Pin, "pow2");
Button AuxButton(BUTTON_AUX, auxPin, "aux");
#endif

And no worries on the both at the same time thing as it’s a Sabine hilt with a rotary button, so you can only physically hit one side or the other. (y) :smiley:

Yep, this looks good to me. Should work perfectly if you can’t physically push both buttons at the same time. :slight_smile:

1 Like

Yeah, Fredrik elaborated/clarified… apologies for not checking back in @Sabersense!

1 Like