why is this not working

#define SW1 18 // pin 1ste drukknop
#define ledPin 13 // pin led
#define SW2 19 // pin 2de drukknop

byte ButtonStateNow1 = 0; // variable om huidige status van de drukknop te bewaren
byte ButtonStateBefore1 = 0; // variable om vroige status van de drukknop te bewaren
byte ButtonStateNow2 = 1;
byte ButtonStateBefore2 = 0;
byte LedisOn = 0; // variabele om te onthouden of de led aan of uit is
int time1 = 0;
int time2 = 0;
void setup() {

pinMode(ledPin, OUTPUT);
digitalWrite(SW1,INPUT);
pinMode(SW2, INPUT);
Serial.begin(9600);
}

void loop()
{

ButtonStateNow1 = digitalRead(SW1); // leest toestand switch 1
ButtonStateNow2 = digitalRead(SW2); // leest toestand sw2
if ((ButtonStateNow1 == HIGH)&&(ButtonStateBefore1 == 0)&&(LedisOn==0)) //stijgende flank en led was uit
{
digitalWrite(ledPin, HIGH);
ButtonStateBefore1 = 1;
LedisOn=1;
time1= millis();
}

else if ((ButtonStateNow2 == HIGH)&&(ButtonStateBefore2 == 0)&&(LedisOn == 1)) // stijgende flank en led was aan
{
digitalWrite(ledPin, LOW);
ButtonStateBefore2 = 1;
LedisOn = 0;
time2= millis();
}
else if ((ButtonStateNow1 == LOW)&&(ButtonStateBefore1 == 1)) // dalende flank
{
ButtonStateBefore1 = 0;
}}

else if ((ButtonStateNow2 == LOW) && (ButtonStateBefore2 == 1)) <------- ^error
{
ButtonStateBefore2 = 0;
}}
if ((time1 != 0)&&(time2 != 0))
{

int verschil = time1 - time2;
if (verschil < 2000);
}}
else if
{
Serial.println(“veel te snel”)

(( verschil < 2000)&&(3000 > verschil))

}}
else if
{
Serial.println(“nog steeds te snel”)
((verschil < 3000)&&(3500 > verschil))
}}
else if
{
Serial.println(“proficiat binnen de tijd”)
((verschil < 35000)&&(4000>))
}}
else if
{
Serial.println(“net te laat”)
((verschil < 4000)&&(4500 > verschil))
}}
else if
{
Serial.println(“veel te laat”)
((verschil < 4500)&&(5000 > verschil))
}}

the error says: E2:46:2: error: expected unqualified-id before ‘else’

else if ((ButtonStateNow2 == LOW) && (ButtonStateBefore2 == 1))

^~~~

E2:49:3: error: expected declaration before ‘}’ token

}}

^

exit status 1
expected unqualified-id before ‘else’

E2.ino (1.95 KB)

  }}

That should never happen

if (verschil < 2000); Nor should that ;

A discussion in the reference about the use of curly brackets ({}).

First of all, you should always make the number of opening curly brackets equals the number of closing curly brackets. That is your first clue there is a problem. You have lots of }} which are causing you issues as well as the premature semicolon after if (verschil < 2000). That line will compile but will accomplish nothing.

ToddL1962:
SNIP The premature semicolon after if (verschil < 2000). That line will compile but will accomplish nothing.

I am going off track here a bit …
I scratch my head over some of this compiler stuff (considering the length of time it has been around, and the trillions of times it has been used).

The compiler will warn me if I have used

if(x=y)

instead of

if(x==y)

Going by that, I would have thought that it could be made to warn me if I presented it with

if(x==y);

And, it begs the question … What does if(x==y); actually compile into?

Steve (still scratching head)

if (x==y); is syntactically and semantically correct. If x and y are the same value then the line of code before the ; is executed. It just happens to be an empty line of code. There is no reason the compiler can’t warn you about it but since it is correct it should proceed to compile it.

ToddL1962:
if (x==y); is syntactically and semantically correct. If x and y are the same value then the line of code before the ; is executed. It just happens to be an empty line of code. There is no reason the compiler can’t warn you about it but since it is correct it should proceed to compile it.

Ah, that makes perfect sense now. There is nothing between ) and ;

Thanks very much indeed.

Steve

thanks for the help everyone!!! I recently started programming

The Arduino IDE will show you the matching brace if you put the cursor next to the brace in question.

thanks alot for the help!

i just finished it and it works

#define SW1 18 // pin 1ste drukknop
#define ledPin 13 // pin led
#define SW2 19 // pin 2de drukknop

byte ButtonStateNow1 = 0; // variable om huidige status van de drukknop te bewaren
byte ButtonStateBefore1 = 0; // variable om vroige status van de drukknop te bewaren
byte ButtonStateNow2 = 1;
byte ButtonStateBefore2 = 0;
byte LedisOn = 0; // variabele om te onthouden of de led aan of uit is
int time1 = 0;
int time2 = 0;
void setup() {

pinMode(ledPin, OUTPUT);
digitalWrite(SW1,INPUT);
pinMode(SW2, INPUT);
Serial.begin(9600);
}

void loop()
{
int verschil = time1 - time2;
ButtonStateNow1 = digitalRead(SW1); // leest toestand switch 1
ButtonStateNow2 = digitalRead(SW2); // leest toestand sw2
if ((ButtonStateNow1 == HIGH)&&(ButtonStateBefore1 == 0)&&(LedisOn==0)) //stijgende flank en led was uit
{
digitalWrite(ledPin, HIGH);
ButtonStateBefore1 = 1;
LedisOn=1;
time1= millis();
}

else if ((ButtonStateNow2 == HIGH)&&(ButtonStateBefore2 == 0)&&(LedisOn == 1)) // stijgende flank en led was aan
{
digitalWrite(ledPin, LOW);
ButtonStateBefore2 = 1;
LedisOn = 0;
time2= millis();
}
else if ((ButtonStateNow1 == LOW)&&(ButtonStateBefore1 == 1)) // dalende flank
{
ButtonStateBefore1 = 0;
}

else if ((ButtonStateNow2 == LOW) && (ButtonStateBefore2 == 1))
{
ButtonStateBefore2 = 0;
}
if ((time1 != 0)&&(time2 != 0))
{

int verschil = time1 - time2;

}
else if(verschil = time1 - time2)
{
Serial.println(“veel te snel”);

(( verschil < 2000)&&(3000 > verschil));

}
else if(verschil = time1 - time2)
{
Serial.println(“nog steeds te snel”);
((verschil < 3000)&&(3500 > verschil));
}
else if(verschil = time1 - time2)
{
Serial.println(“proficiat binnen de tijd”);
((verschil < 35000)&&(4000 > verschil));
}
else if (int verschil = time1 - time2)
{
Serial.println(“net te laat”);

((verschil < 4000)&&(4500 > verschil));
}
else if (int verschil = time1 - time2)
{
Serial.println(“veel te laat”);
((verschil < 4500)&&(5000 > verschil));
}
}