[Help] Switch input to different outputs

Hey guys, I have no clue where I should start with my new project. New to arduio, I know how to wire up but I am at a loss on the coding. Here is the set up if you could point me in the correct direction I would be greatful.

I have a nerf gun that I am trying to add a burst/full auto setup to.
There is the trigger that is the primary input.
I have a a switch that has 3 possessions Single fire/ Burst/ Fully auto
and of course a mosfet that runs the motor

How would I go about getting the board to read what position the switch is in so that when I pull the trigger it will make the necessary adjustments to the time that the motor runs?

So far I am thinking I have to do blink without delay but i am unsure as to how I will get the board to change time based on state of selecter swtich

I'd like to help but I have no idea how a "nerf gun" works so your description means little to me.

What is the specification of the motor you want to drive? Exactly what 3-"possession" (I guess you mean 3-position) switch do you have? Do you really mean that the 3 modes just drive a motor for different lengths of time?

Do you already have the trigger and the motor working with an Arduino? Which Arduino? Please show the wiring and the existing code.

Steve

Okay so I have no code set up but the way the gun works is there is a pair of flywheel motors that rotate clockwise and counterclockwise in the front of the gun, I have this wired with a simple mosfet as they have to be spinning constantly before the firing motor is engaged.

For the firing motor there is just one that runs a belt in turn pushing the foam darts into the flywheels firing them.

So where I am at and mostly scratching my head is the switch is 3-position and has 3 wires attached to it, so my thought is if they all go to separate pins on the arduino nano
then If position 1 true then motor runs for 1000ms
then if position 2 true then motor runs for 3000ms
then if position 3 true then motor runs until trigger switch is released

The trigger switch is what would cause the motor to run but I would like the 3-position switch to determine the length of how long it runs.

I am quite sorry I am new to this, I just need pointed in the right direction. I don't know all of the correct terms and can't really google the proper way to do it. I will work on getting a wiring diagram posted soon, Thank you for the help it is greatly appreciated!

O.k. so you're probably going to need another MOSFET to run the firing motor. What voltage battery do they run on?

But you need to know more about the type of 3-way switch you have. If it only has 3 terminals then it's very likely On - Off - On, so the 3 positions are 1. centre wire connected to one outer wire, 2. no connection, 3 centre connected to the other outer wire. Do you have a multimeter so you can test it?

Once we've worked out exactly what you have the code is likely to be fairly simple. Switching a motor on and off is hardly more complicated than switching an LED and the example "Button" in the IDE will show you how to do that.

BTW if you Google "Arduino nerf gun" you'll find a lot of people have already done various similar sounding projects.

Steve

I have anouther MOSFET the motors are running on a 7.2v system

You are correct about the 3-way switch its OFF-ON-ON 3 wires the OFF connected to the other two ON

My thought is the ground runs through the trigger and to the OFF on the switch where as one of the ON goes to D2 input and the other to D3 Still kind of lost lol

I feel like this is close to what I am looking for

const int switch1Pin = 6;    // switch input 1
const int switch2Pin = 7;    // switch input 2
const int led1Pin = 8;
const int led2Pin = 2;

void setup() {
    // set the switch as an input:
    pinMode(switch1Pin, INPUT); 
    pinMode(switch2Pin, INPUT);
    
    // set all the other pins you're using as outputs:
    pinMode(led1Pin, OUTPUT); 
    pinMode(led2Pin, OUTPUT); 
}

void loop() {
    // if the switch is high, motor will turn on one direction:
    if (digitalRead(switch1Pin) == HIGH) {
    digitalWrite(led1Pin, LOW);   // set leg 1 of the H-bridge low
    digitalWrite(led2Pin, HIGH);  // set leg 2 of the H-bridge high
  } 
    // if the switch is low, motor will turn in the other direction:
  else if(digitalRead(switch2Pin) == HIGH){
    digitalWrite(led1Pin, HIGH);   // set leg 1 of the H-bridge low
    digitalWrite(led2Pin, LOW);   // set leg 2 of the H-bridge low
  }
  else {
    digitalWrite(led1Pin, LOW);   // set leg 1 of the H-bridge low
    digitalWrite(led2Pin, LOW);   // set leg 2 of the H-bridge low    
  }
}

Use INPUT_PULLUP in the pinMode(). This means that LOW=switch pressed.

I think you need 3 inputs. One for the trigger and two for the 3-position switch. Connect the center pin of that switch to ground.

As MorganS says INPUT_PULLUP is what you need. Then your 3 conditions are switch1 is LOW, switch1 and switch2 are HIGH (centre position) or switch2 is LOW.

Then you'll need to get the trigger switch sorted so that you are looking at the changes in the switch state, becoming ON and becoming OFF (look at the "StateChangeDetection" example in the IDE). Otherwise you'll find that after your 1 second run the switch might still be pressed and it will fire again.

Steve

Will have to give it a try, was able to throw this together on break but would I be able to get away with something close to this?

Don't know. I don't open odd links to random websites. The thread "How to use this forum - please read" at the top of every forum gives instructions on how to embed pictures.

Steve

I tried hyperlink didn't work was able to attach download png will have to try from home maybe something with the work computer.

Please don't use F**ing. A pencil-and-paper sketch is always better.