error: expected ';' before ')' token

Hi my name is Nick .I have written the following code in an attempt to turn a led on for varying lengths of time by changing the timer values but I have incurred a number of errors which I am unable to solve.The error messages are attached as a seperate doc . My concept for this code came from an iPad app and I thought it might work

any help would be greatly appreciated
cheers
Nick

 int timer = 500; // put your setup code here, to run once:
 int timer1 = 1000;
 int timer2 = 2000;
 int thisPin = 13;
 
 void setup() {
  // put your main code here, to run repeatedly:
for (int thisPin = 13; thisPin++;);
  pinMode(thisPin,OUTPUT);
  
}

void loop() {
for (int thisPin = 13); thisPin++);
  digitalWrite(thisPin, HIGH);
  delay(timer);
  digitalWrite (thisPin, LOW);  
for (int thisPin = 13); thisPin++);
  digitalWrite(thisPin, HIGH);
  delay(timer1);
  digitalWrite (thisPin, LOW);
for (int thisPin = 13); thisPin++);
  digitalWrite(thisPin, HIGH);
  delay(timer2);
  digitalWrite thisPin, LOW);
}
}

Led test Errors.txt (1.58 KB)

Check all your for statements.

for (int thisPin = 13; thisPin++;);
  pinMode(thisPin,OUTPUT);

Compare the way that your for loops are written versus the syntax in the for loop reference.

Syntax

for( /* init expression */; /*condition */; /* loop */) {
    // one or more statements to be executed
}

or

for( ; ; ) /* single statement to be executed */ ;

Also: having no comments is bad, having wrong comments is worse.

Hi All sorry I havn’t been on in a while. I have re-written the code , which now compiles and works. Thank you for you time and effort in replying. I have done a lot off looking around and I think I understand this code better than my first post Thank you again

//this code now works
 int timer = 200; // create different timer values to use
 int timer1 = 50;
 int timer2 = 100;
 int thisPin = 13;
 
 void setup() {
                 // create a loop, to run repeatedly:
for (int thisPin = 13; thisPin++;);
  pinMode(thisPin,OUTPUT);
 
}

void loop() {
for (int thisPin = 13; thisPin < 14; thisPin++); {
  digitalWrite(thisPin, HIGH);  //turn on
  delay(timer);  //pause/ wait
  digitalWrite (thisPin, LOW); //turn off
delay(timer2);
  digitalWrite(thisPin, HIGH);
  delay(timer1);
  digitalWrite (thisPin, LOW);
delay(timer1);
  digitalWrite(thisPin, HIGH);
  delay(timer2);
  digitalWrite (thisPin, LOW);
   delay(timer2);
}
}

I can guarantee you that code DOES NOT WORK! I'm sure it compiles, but it cannot possibly work correctly....

Regards,
Ray L.

Alright, first of all: in the setup you don’t need to run the loop. In fact, since you don’t have a stoping condition for it, this loop will run indefinitely and try to set all pins up to 2147483647 (the maximum number you can store in an integer).

Second: the for-loop in your loop() section does indeed have a stop-condition, but is completely unneccessary since you do nothing else in your main loop and even if, it yould only run once.

So, just take your two for-loops out, and your program should run as expected.

In fact, since you don't have a stoping condition for it, this loop will run indefinitely and try to set all pins up to 2147483647 (the maximum number you can store in an integer).

In practice the only code that will run because of the for loop is the semicolon following it. However, as thisPin will be out of scope after the for loop the code won't compile anyway.

2147483647 where on Earth did this number come from ?

2147483647 where on Earth did this number come from ?

Sorry, looked at a 32-bit integer. The correct value for a 16-bit integer would be 32767.

Why bother having loops with nothing in them but a null statement (semicolon)?

Your sketch is equivalent to:

//this code now works
int timer = 200; // create different timer values to use
int timer1 = 50;
int timer2 = 100;
int thisPin = 13;


void setup()
{
  // create a loop, to run repeatedly:
  for (int thisPin = 13; thisPin != 0; thisPin++)
  {
    ;
  }
  
  pinMode(thisPin, OUTPUT);
}


void loop()
{
  for (int thisPin = 13; thisPin < 14; thisPin++)
  {
    ;
  }
  
  {
    digitalWrite(thisPin, HIGH);  //turn on
    delay(timer);  //pause/ wait
    digitalWrite (thisPin, LOW); //turn off
    delay(timer2);
    digitalWrite(thisPin, HIGH);
    delay(timer1);
    digitalWrite (thisPin, LOW);
    delay(timer1);
    digitalWrite(thisPin, HIGH);
    delay(timer2);
    digitalWrite (thisPin, LOW);
    delay(timer2);
  }
}

Which is functionally equivalent to this simpler sketch:

int timer = 200; // create different timer values to use
int timer1 = 50;
int timer2 = 100;

const int thisPin = 13;

void setup()
{
  pinMode(thisPin, OUTPUT);
}

void loop()
{
    digitalWrite(thisPin, HIGH);  //turn on
    delay(timer);  //pause/ wait
    digitalWrite (thisPin, LOW); //turn off
    delay(timer2);
    digitalWrite(thisPin, HIGH);
    delay(timer1);
    digitalWrite (thisPin, LOW);
    delay(timer1);
    digitalWrite(thisPin, HIGH);
    delay(timer2);
    digitalWrite (thisPin, LOW);
    delay(timer2);
}

Thank you for your replies . The code may not be well written but it does compile and does run at least on a Freetronics Eleven.
However I can see that is very messy and that it is possible to simplify it greatly and John’s version is now running
cheers
Nick

UKHeliBob:
However, as thisPin will be out of scope after the for loop the code won't compile anyway.

But it will, because there's a global with the same name :frowning:

Solved… thanks