Got frozen on writing

Hey

Im ambicius and just made one of those litle kits ot arduino and want to do more. I need a time killer at my airsoft team HQ and i was thinking on a target.

I´ve searched most of the threads over here but all seem vague

:’( My 1st delema how can i test? im still waiting for some parts to physically built it to test and afraid to burn something and rage quit. Is there a free simulator that gives me and idea if it works? ive found one but its overwellming for a noob like me “proteus”.

The idea its:

Press button > buzzer to prepare de shooter > buzzer + timer in mili starts (4d 7segment display) > 1/5 light turns on and a dedicated switch of the light on a metal/acrillyc its INput > input pressed > another light turns on x15(?)> the loop ends timer stops > long press of the same button or x2press resets timmer

So far only made this cuz i think something is missing :frowning:

//BUTTON's
// constants 
// set pin numbers:
const int buttonPin1 = 2; // the number of the pushbutton pin
const int buttonPin2 = 3;
const int buttonPin3 = 4;
const int buttonPin4 = 5;
const int buttonPin5 = 6;

//all 5 buttons together
const int maxbuttonpins = 5;
int buttonpin[maxbuttonpins] ;

//LED'S
const int LEDPIN1 = 11;      // the number of the LED pin
const int LEDPIN2 = 12;
const int LEDPIN3 = 13;
const int LEDPIN4 = 14;
const int LEDPIN5 = 15;

//all 5 LEDs together
const int maxLedPins = 5;
int ledpins[maxLedPins] = {LEDPIN1, LEDPIN2, LEDPIN3, LEDPIN4, LEDPIN5};

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(LEDPIN1, OUTPUT); 
  pinMode(LEDPIN2, OUTPUT);
  pinMode(LEDPIN3, OUTPUT);
  pinMode(LEDPIN4, OUTPUT);
  pinMode(LEDPIN5, OUTPUT);
  
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin1, INPUT); 
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(buttonPin4, INPUT);
  pinMode(buttonPin5, INPUT);
}

void loop(){
    
    int buttons = 0;
    int leds = 0;
for (int i=0; i<maxbuttonpins; i++)
    {
    if (digitalRead(buttonpin[i])
        buttons |= (1<<i);
    if (digitalRead(ledpins[i])
        leds |= (1<<i);
    }
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin1);
  
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == LOW) {     
    // turn LED on:    
    digitalWrite(LEDPIN1, LOW);
    digitalWrite(LEDPIN2, LOW);
    digitalWrite(LEDPIN3, LOW);
    digitalWrite(LEDPIN4, LOW);
    digitalWrite(LEDPIN5, LOW);
  
} 
  else {
    // KEEP LED ON:
    digitalWrite(LEDPIN1, HIGH);
    digitalWrite(LEDPIN2, LOW);
    digitalWrite(LEDPIN3, LOW);
    digitalWrite(LEDPIN4, LOW);
    digitalWrite(LEDPIN5, LOW);
    
  }
// read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin2);    
    
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == LOW) {     
    // turn LED on:    
    digitalWrite(LEDPIN1, LOW);
    digitalWrite(LEDPIN2, LOW);
    digitalWrite(LEDPIN3, LOW);
    digitalWrite(LEDPIN4, LOW);
    digitalWrite(LEDPIN5, LOW);
  
} 
  else {
    // KEEP LED ON:
    digitalWrite(LEDPIN1, LOW);
    digitalWrite(LEDPIN2, HIGH);
    digitalWrite(LEDPIN3, LOW);
    digitalWrite(LEDPIN4, LOW);
    digitalWrite(LEDPIN5, LOW);
    
  }    
    // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin3);    
    
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == LOW) {     
    // turn LED on:    
    digitalWrite(LEDPIN1, LOW);
    digitalWrite(LEDPIN2, LOW);
    digitalWrite(LEDPIN3, LOW);
    digitalWrite(LEDPIN4, LOW);
    digitalWrite(LEDPIN5, LOW);
  
} 
  else {
    // KEEP LED ON:
    digitalWrite(LEDPIN1, LOW);
    digitalWrite(LEDPIN2, LOW);
    digitalWrite(LEDPIN3, HIGH);
    digitalWrite(LEDPIN4, HIGH);
    digitalWrite(LEDPIN5, HIGH);
    
    
  }
}

1- im thinking that switches are easer to work since only requires GND and power, can make the plates move slightly to activate them

2- the LED- that shows the target can be the same as the switches? that way less wiring and the same goes to LED+?

3- TY for helping me, it will be appreciated

TheManiac:
My 1st delema how can i test?

The easiest test is to hit the Compile button in the Arduino IDE. That will tell you whether you have written valid code or not. I recommend first setting File > Preferences > Compiler Warnings to “All” and then looking at the full contents of the black console window at the bottom of the Arduino IDE window (you may need to scroll up to see it all). Compiler warnings can give you very helpful hints about parts of your code that compile, but may cause problems.

Once your code compiles you still have no guarantee that it works as you intended it to. I don’t know about the simulators. I don’t think there is any substitute for running the code on hardware. You don’t necessarily need all the hardware though. By just adding debug output via Serial.print() statements at critical points in your sketch, you can run the program on your Arduino with the Arduino IDE’s Serial Monitor open (Tools > Serial Monitor) and see what is happening in your sketch. Your code is currently just some buttons and LEDs so I see no reason why you can’t put together a quick prototype on a breadboard to try it out.

Please use code tags when you post code or warning/error messages. To do this, click the </> button on the forum toolbar, then paste the text you want to be in the code tags. Finally, move the cursor out of the code tags before adding any additional text you don’t want to be in the code tags. If your browser doesn’t show the posting toolbar, then you can manually add the code tags like this:
[code]``[color=blue]// your code is here[/color]``[/code]

The reason for doing this is that, without code tags, the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier for us to read your code and to copy it to the IDE or editor.

Using code tags and other important information is explained in the “How to use this forum” post. Please read it.

Please always do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

pert:
The easiest test is to hit the Compile button in the Arduino IDE. That will tell you whether you have written valid code or not. I recommend first setting File > Preferences > Compiler Warnings to “All” and then looking at the full contents of the black console window at the bottom of the Arduino IDE window (you may need to scroll up to see it all). Compiler warnings can give you very helpful hints about parts of your code that compile, but may cause problems.

Once your code compiles you still have no guarantee that it works as you intended it to. I don’t know about the simulators. I don’t think there is any substitute for running the code on hardware. You don’t necessarily need all the hardware though. By just adding debug output via Serial.print() statements at critical points in your sketch, you can run the program on your Arduino with the Arduino IDE’s Serial Monitor open (Tools > Serial Monitor) and see what is happening in your sketch. Your code is currently just some buttons and LEDs so I see no reason why you can’t put together a quick prototype on a breadboard to try it out.

Please use code tags when you post code or warning/error messages. To do this, click the </> button on the forum toolbar, then paste the text you want to be in the code tags. Finally, move the cursor out of the code tags before adding any additional text you don’t want to be in the code tags. If your browser doesn’t show the posting toolbar, then you can manually add the code tags like this:
[code]``[color=blue]// your code is here[/color]``[/code]

The reason for doing this is that, without code tags, the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier for us to read your code and to copy it to the IDE or editor.

Using code tags and other important information is explained in the “How to use this forum” post. Please read it.

Please always do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

TY for the reply even if its not what i hoped, the compilation so far its all ok for what the IDE tells me, but i wanted to know if was working ok, not if the code is right.

I edited the code section, didnt thought on that

TheManiac:
the compilation so far its all ok

Then you must be compiling different code than what you posted here because the code you posted is most definitely not "all ok".

TheManiac:
i wanted to know if was working ok, not if the code is right.

Then wire up some buttons, add some Serial.print() statements and test it out!

TheManiac:
I edited the code section, didnt thought on that

You forgot to do the auto format I requested.