Warum wird die variable komplett hochgezählt?

Ich möchte das bei dem unten geschriebenen Sketch das wen beide Taster gedrückt sind die variable um 1 hochgezählt wird aber wen beide gedrückt sind wird die variable bis 4 hoch gezählt ?

int led1 = 12;
int led2 = 11;
int led3 = 10;
int led4 = 9;
int button = 8;


int tasterstatus = 0;


int i=0;
bool oldButtonState = HIGH;
bool newButtonState;
int count = 0;


int taster=7;
void setup() {
  pinMode(button, INPUT_PULLUP);
  
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);


  pinMode (taster,INPUT_PULLUP);


  Serial.begin (9600);
}


void loop() {
  newButtonState = digitalRead(button);


 tasterstatus = digitalRead(taster);


  if (oldButtonState == HIGH && newButtonState == LOW) {
    count++;
    oldButtonState = newButtonState;


    if (count == 1) {
      digitalWrite(led1, HIGH);
    }
    if (count == 2) {
      digitalWrite(led1, LOW);
      digitalWrite (led2,HIGH);
    }


   if (count == 3){
    digitalWrite (led2,LOW);
    digitalWrite (led3,HIGH);   
   }


   if (count == 4){
    digitalWrite (led3,LOW);
    digitalWrite (led4,HIGH);
   }


   if (count == 5){
    digitalWrite (led4,LOW);
    count = 0;
   }






   if ((tasterstatus == HIGH) && (count = 1)){


    i=1;
   }


   if ((tasterstatus == HIGH) && (count = 2)){
    i=2;
   }


   if ((tasterstatus == HIGH) && (count = 3)){
    i=3;
   }


   if ((tasterstatus == HIGH) && (count = 4)){
    i = 4;
   }




   if (i=1){
    Serial.println ("i 1");
   }
   if (i=2);{
    Serial.println ("i 2");
   }


  if (i = 3){
   Serial.println ("i 3");
  }


  if (i = 4 ){
    Serial.println ("i 4");
  }


    delay(100);
  } else if (oldButtonState == LOW && newButtonState == HIGH) {
    oldButtonState = newButtonState;
  }
}
Computer, Programmieren, arduino, Informatik, Variablen, taster

Meistgelesene Fragen zum Thema Variablen