Coordinating 6 LEDS with variables

Hi, I just got my Arduino and I started a basic laser tag gun to help me learn, now at the moment I haven’t yet implemented IR because that seems a bit above my skill level. However what I have been doing is making the basics of the gun. It can fire 6 shots before pausing to “reload” and then it continues, however my problem is, I’m trying to make LEDs display how many shots it holds however I’m getting multiple errors. I’ve attached the file and help would be much appreciated.

laserBASEv2.ino (1.86 KB)

I liked the part

if(bullets--0) bullets--bullets-1

dave-in-nj: I liked the part

if(bullets--0) bullets--bullets-1

sorry, I'm really new and don't understand

read about if() and syntax.

you start with an if() statement and the delay for 5 seconds. then change the value of bullets to

bullets=bullets-1

the sintax is

if(this == 0) { // the { goes after the end of the line.

you have it before the line

{
if(this==0);

Is this what you want?

const int LED = 13;
const int BUT = 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;
int bullets = 6;
int val = 0;       //set pins and variables

void setup() 

{ 
  pinMode(LED, OUTPUT);
  pinMode(BUT, INPUT);   //set pinmodes
  pinMode(BULL, OUTPUT);
  pinMode(B2, OUTPUT);
  pinMode(B3, OUTPUT);
  pinMode(B4, OUTPUT);
  pinMode(B5, OUTPUT);
  pinMode(B6, OUTPUT);
}

void loop() 
{  
  val = digitalRead(BUT);
  if (val == HIGH)
  {
    if(bullets == 0)
    {
      delay(5000);
    }
    else
    {
      digitalWrite(LED, HIGH);
      delay(250);
      digitalWrite(LED, LOW);
      bullets = bullets - 1;
      delay(1000);
    }
    if(bullets == 6)
    { 
      digitalWrite(BULL, HIGH); 
      digitalWrite(B2, HIGH); 
      digitalWrite(B3, HIGH); 
      digitalWrite(B4, HIGH); 
      digitalWrite(B5, HIGH); 
      digitalWrite(B6, HIGH);
    }
    else

        if(bullets == 5)
      {  
        digitalWrite(BULL, LOW); 
        digitalWrite(B2, HIGH); 
        digitalWrite(B3, HIGH); 
        digitalWrite(B4, HIGH); 
        digitalWrite(B5, HIGH); 
        digitalWrite(B6, HIGH);
      }
      else

          if(bullets == 4)
        {   
          digitalWrite(BULL, LOW); 
          digitalWrite(B2, LOW); 
          digitalWrite(B3, HIGH); 
          digitalWrite(B4, HIGH); 
          digitalWrite(B5, HIGH); 
          digitalWrite(B6, HIGH);
        }
        else

            if(bullets == 3)
          {    
            digitalWrite(BULL, LOW); 
            digitalWrite(B2, LOW); 
            digitalWrite(B3, LOW); 
            digitalWrite(B4, HIGH); 
            digitalWrite(B5, HIGH); 
            digitalWrite(B6, HIGH);
          } 
          else

              if(bullets == 2)
            { 
              digitalWrite(BULL, LOW); 
              digitalWrite(B2, LOW); 
              digitalWrite(B3, LOW); 
              digitalWrite(B4, LOW); 
              digitalWrite(B5, HIGH); 
              digitalWrite(B6, HIGH);
            }
            else

                if(bullets == 1)
              {  
                digitalWrite(BULL, LOW); 
                digitalWrite(B2, LOW); 
                digitalWrite(B3, LOW); 
                digitalWrite(B4, LOW); 
                digitalWrite(B5, LOW); 
                digitalWrite(B6, HIGH);
              } 
              else

                  if(bullets == 0)
                {   
                  digitalWrite(BULL, LOW); 
                  digitalWrite(B2, LOW); 
                  digitalWrite(B3, LOW); 
                  digitalWrite(B4, LOW); 
                  digitalWrite(B5, LOW); 
                  digitalWrite(B6, LOW);
                }       



  }
  else
  {
    digitalWrite(LED, LOW);
  }  
}

BillHo: Is this what you want?

const int LED = 13;
const int BUT = 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;
int bullets = 6;
int val = 0;       //set pins and variables

void setup()

{   pinMode(LED, OUTPUT);   pinMode(BUT, INPUT);  //set pinmodes   pinMode(BULL, OUTPUT);   pinMode(B2, OUTPUT);   pinMode(B3, OUTPUT);   pinMode(B4, OUTPUT);   pinMode(B5, OUTPUT);   pinMode(B6, OUTPUT); }

void loop() {    val = digitalRead(BUT);   if (val == HIGH)   {     if(bullets == 0)     {       delay(5000);     }     else     {       digitalWrite(LED, HIGH);       delay(250);       digitalWrite(LED, LOW);       bullets = bullets - 1;       delay(1000);     }     if(bullets == 6)     {       digitalWrite(BULL, HIGH);       digitalWrite(B2, HIGH);       digitalWrite(B3, HIGH);       digitalWrite(B4, HIGH);       digitalWrite(B5, HIGH);       digitalWrite(B6, HIGH);     }     else

        if(bullets == 5)       {
        digitalWrite(BULL, LOW);         digitalWrite(B2, HIGH);         digitalWrite(B3, HIGH);         digitalWrite(B4, HIGH);         digitalWrite(B5, HIGH);         digitalWrite(B6, HIGH);       }       else

          if(bullets == 4)         {
          digitalWrite(BULL, LOW);           digitalWrite(B2, LOW);           digitalWrite(B3, HIGH);           digitalWrite(B4, HIGH);           digitalWrite(B5, HIGH);           digitalWrite(B6, HIGH);         }         else

            if(bullets == 3)           {
            digitalWrite(BULL, LOW);             digitalWrite(B2, LOW);             digitalWrite(B3, LOW);             digitalWrite(B4, HIGH);             digitalWrite(B5, HIGH);             digitalWrite(B6, HIGH);           }           else

              if(bullets == 2)             {               digitalWrite(BULL, LOW);               digitalWrite(B2, LOW);               digitalWrite(B3, LOW);               digitalWrite(B4, LOW);               digitalWrite(B5, HIGH);               digitalWrite(B6, HIGH);             }             else

                if(bullets == 1)               {
                digitalWrite(BULL, LOW);                 digitalWrite(B2, LOW);                 digitalWrite(B3, LOW);                 digitalWrite(B4, LOW);                 digitalWrite(B5, LOW);                 digitalWrite(B6, HIGH);               }               else

                  if(bullets == 0)                 {
                  digitalWrite(BULL, LOW);                   digitalWrite(B2, LOW);                   digitalWrite(B3, LOW);                   digitalWrite(B4, LOW);                   digitalWrite(B5, LOW);                   digitalWrite(B6, LOW);                 }     

  }   else   {     digitalWrite(LED, LOW);   }  }

Yes, thanks

dave-in-nj: read about if() and syntax.

you start with an if() statement and the delay for 5 seconds. then change the value of bullets to

bullets=bullets-1

the sintax is

if(this == 0) { // the { goes after the end of the line.

you have it before the line

{ if(this==0);

Ok, thanks