Doubt about error Else without a previuos if, in serial communication between two arduinos

Asked

Viewed 24 times

0

I’m making a communication, serial in tinkercad simulator, between two Inuit, my code is displayed, error:

Else without a previuos if

The idea of the program is to press button, in the emitter Arduino is to light led in the emitter and second led , in the other Arduino, receiver by serial communication..

Arduino emissor

void setup() {

  Serial.begin(9600);
  pinMode(11,INPUT);
  pinMode(10,OUTPUT);
}

void loop() {

  if(digitalRead(11)){
   digitalWrite(10,1);
   Serial.println(255);
  }
  else{
   digitalWrite(10,0);
   Serial.println(0);
  }
  delay(100);

}

Arduino receiver

void setup() {

  Serial.begin(9600);
  pinMode(8,INPUT);
  pinMode(10,OUTPUT);
  int value;
}

void loop() {
  while (Serial.available() > 0) {

    int value = Serial.parseInt();
    Serial.println(value);


    if ( value == 255);{
        digitalWrite(10,1);


    }else {
      digitalWrite(10,0);  
    }
  }
}
  • The error is in your code if ( value == 255);{ see the ; in an incorrect location.

  • vlw! Celso was this msm, breaking his head with beast thing! thank you

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.