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.)
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.
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.)
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.