Controll my code

could someone check my code please and give me a feedback?


int pyro1 = 20;
int pyro2 = 21;
int pyro3 = 22;
int pyro4 = 23;

int led_red = 14;
int led_ylw = 15;
int led_grn = 16;
int buzzer = 10;

int button1 = 17;
int button2 = 19;
int button3 = 187;
int button4 = 150;
int buttonR = 69;

int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonStateR = 0;

int state;

void setup() {
  // setup pinMode Pyro 1-4
  pinMode(pyro1, OUTPUT);
  pinMode(pyro2, OUTPUT);
  pinMode(pyro3, OUTPUT);
  pinMode(pyro4, OUTPUT);
    
    // setup pinMOde LED/Buzzer
      pinMode(led_red, OUTPUT);
      pinMode(led_ylw, OUTPUT);
      pinMode(led_grn, OUTPUT);
    
      pinMode(buzzer, OUTPUT);

        // setup pinMode button
          pinMode(button1, INPUT);
          pinMode(button2, INPUT);
          pinMode(button3, INPUT);


            //digitalwrite, Low sicherheit
              digitalWrite (pyro1, LOW);
              digitalWrite (pyro2, LOW);
              digitalWrite (pyro3, LOW);
              digitalWrite (pyro4, LOW);

                Serial.begin(9600);
}

void loop() {
  state = 0;
/* test of system

  buttonStateR = digitalRead(buttonR);

  if (buttonStateR == HIGH);{
    
        buttonState4 = digitalRead(button4);
        
           while (buttonState4 ==HIGH){
            
            tone(buzzer,450);
            delay(1000);
            noTone(buzzer);
            delay(1000) ;
           }            
                digitalWrite(led_red, HIGH);
                delay(500);
                digitalWrite(led_red, LOW);
                delay(500);
              
                digitalWrite(led_ylw, HIGH);
                delay(500);
                digitalWrite(led_ylw, LOW);
                delay(500);
              
                digitalWrite(led_grn, HIGH);
                delay(500);
                digitalWrite(led_grn, LOW);
                delay(500);
                
                  tone(buzzer, 450);
                  delay(500);
                  noTone(buzzer);
                  delay(500);
                
                  tone(buzzer, 450);
                  delay(500);
                  noTone(buzzer);
                  delay(500) ;
               
                  tone(buzzer,450);
                  delay(500);
                  noTone(buzzer);
                  delay(500) ;
                
 }
 else {
     state = 0;
 }

 */
 
      
state = 1; //ground idle 
digitalWrite (pyro1, LOW);
digitalWrite (pyro2, LOW);
digitalWrite (pyro3, LOW);
digitalWrite (pyro4, LOW);
              
digitalWrite (led_red, HIGH);
digitalWrite (led_ylw, HIGH);
digitalWrite (led_grn, HIGH);

  buttonState1 = digitalRead(button1);

  if (buttonState1 == HIGH) {
    digitalWrite (led_red, LOW);
    digitalWrite (led_ylw, LOW);
    digitalWrite (led_grn, LOW);
    state = state + 1;
      } else {
       state = 1;
    }

state = 2;  //ground chil
  
    digitalWrite(led_ylw, HIGH);
    
  
       buttonState2 = digitalRead(button2);
       
// when ignition isn't initialized by roket itself
          if (buttonState2 == LOW) {
             
            digitalWrite(led_ylw, LOW);  
            
            state = state + 1;
            
          } else {
            
            state = 2;
          }
// later:detection odf liftoff with altimeter

// when ignition is initialized by roket itself  
/*          if (buttonState2 == HIGH) {
            
            digitalWrite(led_ylw, LOW);  
            digitalWrite (pyro2, HIGH); //insert name of selectet pyro channel for egnition
            errorCheck;
            state = state + 1;
            
          } else {
            
            state = 2;
          }
 */
 //here you acan selct the way, how the main roketmotor is egnited.
                     
state = 3;  //powered acent

    digitalWrite(led_grn, HIGH);

     delay (2100); //delay = burning time of roket motor

     
      state = state + 1;

// later : detect apogee
     
state = 4;  //unpowered acent
  delay (2000); //delay = approximately time of free coasting (upwards)

      state = state + 1;
      

state = 5;  //unguided decent
  delay (2000); //time  of free costing after apogeee

      state = state + 1;
      

state = 4;  //decent on paracute active
  digitalWrite (led_grn, LOW);

    digitalWrite (led_red, HIGH);

     digitalWrite (pyro1, HIGH);
     delay(5000);
     digitalWrite (pyro1, LOW);
     delay(1000);

       state = state + 1;
       
        digitalWrite (led_red, LOW);

state = 6; //parachute decent + touchdown
delay(6000);

    buzzerAL;
        state = 6;
}


void buzzerAL (){
      tone(buzzer,450);
      delay(500);
      noTone(buzzer);
      delay(500) ;
  buzzerAL;
}


void errorCheck (){

  buttonState3 = digitalRead(button3);

  if (buttonState3 == HIGH) {
    if ( state > 1){
          state = 0;
     digitalWrite (led_red, HIGH); 
     digitalWrite (led_grn, HIGH);
     digitalWrite (led_ylw, HIGH);
     delay(500); 
     digitalWrite (led_red, LOW);
     digitalWrite (led_grn, LOW);
     digitalWrite (led_ylw, LOW);
     delay(500);
     digitalWrite (led_red, HIGH);
     digitalWrite (led_grn, HIGH);
     digitalWrite (led_ylw, HIGH);
     delay(500);
     digitalWrite (led_red, LOW); 
     digitalWrite (led_grn, LOW);
     digitalWrite (led_ylw, LOW);
     delay(500);
     digitalWrite (led_red, HIGH);
     digitalWrite (led_grn, HIGH);
     digitalWrite (led_ylw, HIGH);
     delay(500);
     digitalWrite (led_red, LOW);
     digitalWrite (led_grn, LOW);
     digitalWrite (led_ylw, LOW);
     delay(500);

    
   
     }else{
      digitalWrite (pyro1, HIGH);
      digitalWrite (pyro2, HIGH);
      digitalWrite (pyro3, HIGH);
     }
  }
   
}

I am new in the World of coding so please forgive me abou obivously misakes :wink:

Your post was MOVED to its current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.

buzzerAL;

what is it?

int button3 = 187;
  pinMode(button3, INPUT);
  buttonState3 = digitalRead(button3);

How many pins does your Arduino have ?

i want to create a loop so at the end of the code the buzzer ceeps beeping, and aso when error Check is triggered( it isnt in the code yet) it also will ceep beeping.
idk if it is te right way.

thex are just random numbers LOL. i work with a teensy3.2 and donk know the pins yet

do you speak German?

yea i do

void buzzerAL () {
  tone(buzzer, 450);
  delay(500);
  noTone(buzzer);
  delay(500) ;
  buzzerAL;
}

pass auf. das ist eine Funktion und am Ende du schreibst die gleiche Name ohne Klammern.
das ist Unsinn.

Thanks for letting us know before we were asked to comment

Why are so many of the variables declared as int when their values will never exceed 255 so could be byte. Maybe they are just random data types

Why aren't variables that will never change, such as pin numbers, declared as const ?

How are the inputs wired ?
Any pullup or pulldown resistors in place and if not, why not ?

okey danke, wie kann ich dann diese Funktion als Schlaufe laufen lassen, also wenn sie aktiviert wird, läuft sie bis ins Unendliche?

Do you want this topic moved to the German forum category ?

how is the correct way to declare a pin number?
such as a LED ore a button?

yea there are

that would be nice tank you, Im sorry for making trouble

#define somePin 13
da die Pinnummer wird nicht im Laufe des Programms geändert, sollte sie auch kein Speicher verbrauchen. deshalb wird sie keine Variable zugeordnet bekommen.

Topic moved as requested by @radamski

okey danke
also int nur für sich welchselnde Vriablen und alle pin-bezeichnugen mit #define

weiter hin, um alles übersichtlicher zu machen, könnte man die Teile die sich wiederholen, in eine getrennte Funktion raus schreiben. Z.B.:

void AlleLED_hell(){
  digitalWrite(10, HIGH);
  digitalWrite(11, HIGH);
  ...

}

dann schribe ich im Coe einfach:

....

alleLED_hell;

..

und dann wird es automatisch ausgeführt?

alleLED_hell();

um noch weniger zu schreiben und kopieren, könnte man Port Manipulation nutzen
https://www.arduino.cc/en/Reference/PortManipulation
könnte sein dass es bei Teency ähnlich ist