Code isn't working, no errors

Or

if(X=0 && millis() - millis3second > 3000) { // some code }

Ok, so I fixed some stuff, it now can be fired however the LED stays on too long, I'm also currently adding 3 second delay on push button, thanks to larry

const int LED = 13;
const int BUTTON = 7;
const int BULL = 2;
const int B2 = 3;
const int B3 = 4;
const int B4 = 5;
const int B5 = 6;
const int B6 = 9;
const int OUT = 8;
const int HIT = 10;
int bullets = 6;
int val = 0;  //set pins and variables
int hit = LOW;
int reloading = 0;
unsigned long previousMillis = 0;
unsigned long previousMillis2 = 0;
unsigned long previousMillis3 = 0;
unsigned long previousMillis4 = 0;
unsigned long interval = 1000;
unsigned long interval2 = 1250;
unsigned long interval3 = 3000;
unsigned long int1 = 10;
unsigned long int2 = 0;

void setup()
{
 pinMode(LED, OUTPUT);
 pinMode(BUTTON, INPUT);   //set pinmodes
 pinMode(BULL, OUTPUT);
 pinMode(B2, OUTPUT);
 pinMode(B3, OUTPUT);
 pinMode(B4, OUTPUT);
 pinMode(B5, OUTPUT);
 pinMode(B6, OUTPUT);
 pinMode(OUT, OUTPUT);
 pinMode(HIT, INPUT);
}

void loop()
{
 unsigned long currentMillis = millis(); //set currentMillis to millis
 val = digitalRead(BUTTON); //set val to BUTTON
 hit = digitalRead(HIT); //set hit to HIT
 if ((currentMillis - previousMillis3 > int1) && (hit == HIGH)) // checkig if button is being pressed and whether 10ms has passed
 {
   delay(10000); //delay the program for 10 seconds, this is how you go out
 }
 else if (bullets == 0) //otherwise check if there is no bullets
 {
   reloading = reloading + 1; //add 1 to reloading
      //need to add a 3 second delay here
      //record time when it began
      //stop when 3 seconds has passed
   
   bullets = bullets + 6; //add 6 to bullets
   reloading = reloading - 1; //take 1 from reloading
 }
 else if (((currentMillis - previousMillis > interval) && (val == HIGH) && (reloading == 0))) //otherwise check if you're not reloading, button is pushed and 1 second has passed
 {
   previousMillis = currentMillis; //make currentMillis previousMillis
   digitalWrite(LED, HIGH); //turn on the LED
   bullets = bullets - 1; //take away 1 bullet
 }
 if (currentMillis - previousMillis > interval2) //wait 250 milliseconds (doesn't work)
 {
   previousMillis = currentMillis; //make currentMillis previousMillis
   digitalWrite(LED, LOW); //turn off the LED
 }
}
[CODE]

LarryD:
At the point X=0 you make millis3second = millis()

then you can:

if(X == 0 && millis() - millis3second < 3000)
{
return; // and/or some other stuff you need
}

Sorry, could you explain the if(x == o) a bit more, I don’t really understand

I was attempting to answer your question in post #18

If X is your variable in post #18 and it reaches 0 as you say in #18 then you can initialize a timing variable: unsigned long millis3seconds; . . . if(X==0) { millis3secoands = millis(); // capture the current controller on time }

then later in your code you can use this in a timing calculation to see if 3000ms or 3 seconds has gone by. as mentioned: if(X==0 && millis() - millis3seconds > 3000) // this will be true only after 3 seconds have gone by { // you can then execute some instructions as 3 seconds now have gone by // for example you can make X = 6 X = 6; }

Hey, I’ve updated my code and now I’ve got two problems, firstly, when it fires the LED doesn’t turn off and secondly when fire was working when it reloaded it wouldn’t start up again

const int LED = 13;
const int BUTTON = 7;
const int BULL = 2;
const int B2 = 3;
const int B3 = 4;
const int B4 = 5;
const int B5 = 6;
const int B6 = 9;
const int OUT = 8;
const int HIT = 10;
int bullets = 6;
int val = 0;  //set pins and variables
int hit = LOW;
int reloading = 0;
unsigned long previousMillis = 0;
unsigned long millis3seconds = 0;
unsigned long previousMillis3 = 0;
unsigned long millisLED = 0;
unsigned long interval = 1000;
unsigned long interval2 = 250;
unsigned long interval3 = 3000;
unsigned long int1 = 10;
unsigned long int2 = 0;

void setup()
{
  pinMode(LED, OUTPUT);
  pinMode(BUTTON, INPUT);   //set pinmodes
  pinMode(BULL, OUTPUT);
  pinMode(B2, OUTPUT);
  pinMode(B3, OUTPUT);
  pinMode(B4, OUTPUT);
  pinMode(B5, OUTPUT);
  pinMode(B6, OUTPUT);
  pinMode(OUT, OUTPUT);
  pinMode(HIT, INPUT);
}

void loop()
{
  unsigned long currentMillis = millis(); //set currentMillis to millis
  val = digitalRead(BUTTON); //set val to BUTTON
  hit = digitalRead(HIT); //set hit to HIT
  if ((millis() - previousMillis3 > int1) && (hit == HIGH)) // checkig if button is being pressed and whether 10ms has passed
  {
    delay(10000); //delay the program for 10 seconds, this is how you go out
  }
  else 
  if (bullets == 0) //otherwise check if there is no bullets
  {
    reloading = 1; //add 1 to reloading
       millis3seconds = millis();
       digitalWrite(OUT, HIGH);
       if(bullets = 0 && millis() - millis3seconds > 3000)
    bullets = 6; //add 6 to bullets
    reloading = 0; //take 1 from reloading
    digitalWrite(OUT, LOW);
  }
  else 
  if (((millis() - previousMillis > interval) && (val == HIGH) && (reloading == 0))) //otherwise check if you're not reloading, button is pushed and 1 second has passed
  {
    previousMillis = currentMillis; //make currentMillis previousMillis
     millisLED = millis();
    digitalWrite(LED, HIGH); //turn on the LED
    bullets = bullets - 1; //take away 1 bullet
  
  if (millis() - millisLED > interval2) //wait 250 milliseconds (doesn't work)
  {
    digitalWrite(LED, LOW); //turn off the LED
  }
  }
}

You have the blocks wrong, that is your { and } are not right.

Your problem is that you are trying to do it all in the loop function. Separate the timing from the action. Make the action into functions so you can see the timing.

Grumpy_Mike: You have the blocks wrong, that is your { and } are not right.

Your problem is that you are trying to do it all in the loop function. Separate the timing from the action. Make the action into functions so you can see the timing.

how would I do that?

In the loop function just have a simple sequence of if statements. Each one simply calls a function. No else at all.

Each if statement should have two parts. 1) am I waiting to do this action? 2) is it time to do this action? Only when the two parts are satisfied then do the action.

The first part is normally done with a count variable sometimes called a state variable or Boolean variables. The action functions not only do the actions but set up the time reference to do the next action but also the variable that says what action is to come next.

The loop function simply cycles through all these if statements seeing what function to call next. Most of the time this will be nothing.