When Two Buttons is One Button

I want to wire up a hilt so that it can either be set to run with normal two-button configs, or one button configs with the Power button duplicated, and I just want to check the syntax.

Will this do it:

#define NUM_BUTTONS 1

Button PowerButton(BUTTON_POWER, powerButtonPin, "pow");
Button PowerButton(BUTTON_POWER, auxPin, "aux");

Thanks in advance.
:slight_smile:

That should give you a compile error (double define error), I think?
But you could try:

#define NUM_BUTTONS 2

Button PowerButton(BUTTON_POWER, powerButtonPin, "pow1");
// Button "name" ("EVENT_RELEASED", pin, "message for serial monitor"
// don't change the button names (decide which event will be released, choose correct pin, "message for serial monitor can be whatever you want")
Button AuxButton(BUTTON_POWER, auxPin, "pow2");

You can have 2 buttons “doing the same thing” but your prop would have to be modified to accommodate the fact that they do the same thing.
Or you’d need to wire them both in parallel (same pin & NUM_BUTTONS 1)

As oliverflying points out, they can’t be named the same “PowerButton” but other than that it should work.

No need, it should just work.

Should it though?

The prop relies heavily on ifdefs that point to NUM_BUTTONS, like
#if NUM_BUTTONS == 1
If I specify two buttons, at the CONFIG_TOP section, it will only compile two button controls.
Or do I need to specify
#define NUM_BUTTONS 1
even though there are two lines under CONFIG_BUTTONS?

This.
Basically, you want it to function as a 1-button saber, and you’re only feeding the prop events from one button.
The only weird part can be that if you press one button, then the other, there is a possibility that the prop gets a but confused, but chances are fairly low, and you can just avoid doing that next time…

2 Likes

Got it!
Thanks guys - appreciated as always.
:slight_smile:

Just in case you missed, you’ll have to change the second button to be “BUTTON_AUX” if you want to use as a 2 button. If the both buttons are set to BUTTON_POWER in the CONFIG_BUTTONS section you’ll never trigger the second (Aux) control.

Button AuxButton(BUTTON_AUX, auxPin, "aux");

That is why I thought that your prop might need to be modified to accommodate.

But if I understand correctly:

#define NUM_BUTTONS 1 (unlike NUM_BLADES) doesn’t “care” how many buttons are defined in CONFIG_BUTTONS, is that correct ?

That is correct.
NUM_BUTTONS is a hint for the prop. The prop may ignore that hint.
Nothing fails at compilation time if you define more or less than NUM_BUTTON buttons in CONFIG_BUTTONS, but some of your buttons might not work.

1 Like