electronic trigger with mode select

hi, im using an arduino uno. im trying to make a trigger for my paintball gun. id like to be able to use a single switch to toggle between full auto/ semi auto. im going to use the arduino to replace the electronics in my paintball gun. so far this is my code that ive cut/pasted/written

int button1 = A1;
int button2 = A2;
int triggerswitchpin = 7;
int solenoidpin = 5;

int mode1;
int mode2;

int mode;

int redLED = 5;
int blueLED = 12;

boolean running = false;

void setup()
{
 digitalWrite(triggerswitchpin,HIGH);
 pinMode (solenoidpin, OUTPUT);  //output voltage to solenoid
 pinMode(redLED, OUTPUT);
 pinMode(blueLED, OUTPUT);
 Serial.begin(9600);
}

void loop()
{
 mode1 = digitalRead(button1);
 mode2 = digitalRead(button2);
 
 
 if (mode1 == HIGH) { mode = 1; }
 if (mode2 == HIGH) { mode = 2; }
  
 if (mode == 1)
   {
if (digitalRead(triggerswitchpin) == HIGH)
delay(20);        //delay to debounce switch
running = !running;    //toggle running variable
digitalWrite(solenoidpin,running);   //sends signal to solenoid
delay (20); //dwell time for solenoid
      }
   
 if (mode == 2)
   {
     digitalWrite(redLED, LOW);
     digitalWrite(blueLED, HIGH);      
   }
  
     
     
 Serial.println(mode);

 
}

right now i have a relay setup on pin 5 and use pin 7 as a trigger. except when i get into the mode with the script it start operating the trigger right away. im a total newbie at programming so can someone please help me. for instance, i would like to use digital pin 7 as the trigger input. with the solenoid output on pin 5. but at the same tiem i would like to be able to hit a button connected to some other pin to switch to a whole other part of the script to switch to semi auto, 3 round burst and full auto. i hope someone can help me out. maybe someone could give me an example what said code might look like?? ive tried alot of things but im not have the best of luck. thanks everyone

You need to look at the state change detection example. You care about when the trigger switch BECOMES pressed, not IS pressed.

And before posting again you need to look at How to use the forum :wink:

thanks guys, i have completed the state change example. i have the switch connect with the pull down resistor and it operates. i have looked at alot of other people projects that used a button as mode switch. just to get some output i stitched together some of their scripts. i had the mode selection switch setup and it would switch modes but it would run my code properly to operate the trigger solenoid. it would either keep looping hte code and running it without the trigger switch or it would just not function properly. could someone maybe write me some example code. something like,

2 modes that i can select by pressing a button

one of the modes if fully automatic

other mode semi automatic.

right now im just operating a relay instead of a gun so nothing needs to be perfect. im having a hard time getting the full auto part to work properly. so for the full auto mode i just need on/off/on/off untill i let off the trigger button. it dont need to be fast or perfect. just something for me to get started with. thankyou

if i had to write a example off the top of my head "which i cannot do" i would want it to be something like,

int relay
int trigger
int modeswitch

}

void setup(

pinmode(trigger, input
pinmode(relay,output
pinmode(modeswitch,input


void loop(

if modeswitch pressed, switch mode 2
if mode =2 stay at mode 2
if modeswitch pressed again, switch mode 1
if mode 1 stay at mode 1
}

mode=1(
if trigger=high
digitalwrite, relay on
delay(20);
digitalwrite,relay off
"then keep repeating until trigger=low"??

mode=2(
digitalwrite. relay on
delay(20);
digitalwrite, relay off
stay off.

thanks again.!!

okay i think i might be figuring it out now