3 position switch compatibility

I wasn’t sure where this put in, but being wiring, thought I would try here. I also searched and didn’t see what I was looking for.

I have an E11 blaster kit I need to start on and plan the electronics out. It came with a fire selector switch in the grip. I has 4 pins - G, 1, 2, 3. (I assume, I need to meter it)

Is the blaster prop ready for this kind of switch to set stun/kill/auto? How would I wire that?
Maybe G to GND, “stun” position to BTN1, “fire” to BTN2, and “auto” to BTN3? That would essentially change any position to a long press, so I assume some prop changes are needed.

No, but it wouldn’t be that hard to fix.
Easiest thing would be to set it up as three latching switches, and then you would need to add some cases to the prop to make it work. (Latching switches only have EVENT_LATCH_ON and EVENT_LATCH_OFF, no long-, short- or double-clicks.)

I also realized I would need the 2 regular buttons as well.

Would I set these buttons in the config for the blaster? Something like this:

#ifdef CONFIG_BUTTONS
Button PowerButton(BUTTON_POWER, powerButtonPin, "pow");
Button AuxButton(BUTTON_AUX, auxPin, "aux");
Button LatchingButton(BUTTON_1, aux2Pin, "b1");
Button LatchingButton(BUTTON_2, rxPin, "b2");
Button LatchingButton(BUTTON_3, txPin, "b3");
#endif

There is no BUTTON_1/2/3.
You can see all the available button names here:

For a blaster, you probably want BUTTON_FIRE, but beware that it as the same number as BUTTON_UP and BUTTON_TRIGGER_FOUR

Now the good news is that latching events are not the same as regular button events, so you can actually re-use the same button IDs for this switch, and it would still work.

For instance, you could use BUTTON_TRIGGER_ONE/TWO/THREE for the three latching buttons, but you would have to make sure that there are no latching events for BUTTON_POWER in your prop, since it would be the same as BUTTON_TRIGGER_ONE.

1 Like

It occurs to me that two latching switches might be enough.
If neither is “on”, then it must be the third state.

Resurrecting this thread a bit…

I admit I am not fully sure what this means, but here is what I have for the button config:

#ifdef CONFIG_BUTTONS
Button PowerButton(BUTTON_FIRE, powerButtonPin, "fire");
Button AuxButton(BUTTON_AUX, auxPin, "aux");
Button LatchingButton(BUTTON_TRIGGER_ONE, free1Pin, "s1");
Button LatchingButton(BUTTON_TRIGGER_TWO, free2Pin, "s2");
Button LatchingButton(BUTTON_TRIGGER_THREE, free3Pin, "s3");
#endif

Would this work with the blaster.h prop?

How many buttons should I define?

First of all, I think you meant this:

#ifdef CONFIG_BUTTONS
Button PowerButton(BUTTON_FIRE, powerButtonPin, "fire");
Button AuxButton(BUTTON_AUX, auxPin, "aux");
LatchingButton S1(BUTTON_TRIGGER_ONE, free1Pin, "s1");
LatchingButton S2(BUTTON_TRIGGER_TWO, free2Pin, "s2");
LatchingButton S3(BUTTON_TRIGGER_THREE, free3Pin, "s3");
#endif

BUTTON_TRIGGER_ONE is an alias for BUTTON_POWER
BUTTON_TRIGGER_TWO is an alias for BUTTON_AUX
BUTTON_TRIGGER_THREE is an alias for BUTTON_AUX2

blaster.h already has some cases for BUTTON_POWER/BUTTON_TRIGGER_ONE, but not for the other two.

I think you can skip the “s1” pin and only wire up two wires to the switch. If neither is “on”, then you just assume that the third one is. You’ll need to add some code for this anyway. (Which I can help with if you need it.)

1 Like

Programming aside, I would like to get it wired up soon. I metered the pins and there is no common ground. :frowning:

In the first position pin 1 and 2 are shorted, next pin 2 and 3 shorted, next pin 3 and 10 shorted.

Would this wiring diagram be able to utilize these pins for selection (once I figure out how to program it)? It also has some info on the selector.

The pins connect to free1, free2, and free3.

Just connect “2” to ground.
The code will then do something like:

// Do this once
inputMode(1, INPUT_PULLUP);
inputMode(3, INPUT_PULLUP);

// Do this repeatedly (in loop)
if (digitalRead(1))
  target_mode = FIRE;
else if(digitalRead(3))
  target_mode = STUN;
else
  target_mode = AUTO;

Then all it needs is a bit of delay before setting the mode, otherwise it will switch several times when you move from one selection to another.