expected identifier before '(' token

Hello,

I'm new at this.

I made a sketch for my blinds.
But got following message:

expected identifier before '(' token.

I searched for a couple of hours, and tried several things, but can't find the solution.

What's wrong in the sketch?

/*
  Smoothing

  Reads repeatedly from an analog input, calculating a running average and
  printing it to the computer. Keeps ten readings in an array and continually
  averages them.

  The circuit:
  - analog sensor (potentiometer will do) attached to analog input 0

  created 22 Apr 2007
  by David A. Mellis  <dam@mellis.org>
  modified 9 Apr 2012
  by Tom Igoe

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Smoothing
*/

// Define the number of samples to keep track of. The higher the number, the
// more the readings will be smoothed, but the slower the output will respond to
// the input. Using a constant rather than a normal variable lets us use this
// value to determine the size of the readings array.
const int numReadings = 10;

int readings[numReadings];  // the readings from the analog input
int readIndex = 0;          // the index of the current reading
int total = 0;              // the running total
int average = 0;            // the average

int inputPin = A0;
int state = 0;

//Motor A
const int motorPin1  = 9;   // Pin 14 of L293
const int motorPin2  = 10;  // Pin 10 of L293
//Motor B
const int motorPin3  = 6; // Pin  7 of L293
const int motorPin4  = 5;  // Pin  2 of L293

void setup() {
  // initialize serial communication with computer:
  Serial.begin(9600);
  // initialize all the readings to 0:
  for (int thisReading = 0; thisReading < numReadings; thisReading++) {
    readings[thisReading] = 0;
  }
}

void loop() {
  // subtract the last reading:
  total = total - readings[readIndex];
  // read from the sensor:
  readings[readIndex] = analogRead(inputPin);
  // add the reading to the total:
  total = total + readings[readIndex];
  // advance to the next position in the array:
  readIndex = readIndex + 1;

  // if we're at the end of the array...
  if (readIndex >= numReadings) {
    // ...wrap around to the beginning:
    readIndex = 0;
  

  // calculate the average:
  average = total / numReadings ;
  // send it to the computer as ASCII digits
  Serial.println(average);
  delay(1000);        // delay in between reads for stability
  }



 
if (average >= 600) && (state == 0)


{
    //This code  will turn Motor A + B counterclockwise for 5 sec.
    analogWrite(motorPin1, 0);
    analogWrite(motorPin2, 254);
    analogWrite(motorPin3, 0);
    analogWrite(motorPin4, 254);
    delay(5000);
    state = 1; // blinds are closed


 //And this code will stop motors
    analogWrite(motorPin1, 0);
    analogWrite(motorPin2, 0);
    analogWrite(motorPin3, 0);
    analogWrite(motorPin4, 0);
}

else if (average <= 500) && (state == 1)


{
    //This code  will turn Motor A + B clockwise for 5 sec.
    analogWrite(motorPin1, 254);
    analogWrite(motorPin2, 0);
    analogWrite(motorPin3, 254);
    analogWrite(motorPin4, 0);
    delay(5000);
    state = 0; // blinds are open

    //And this code will stop motors
    analogWrite(motorPin1, 0);
    analogWrite(motorPin2, 0);
    analogWrite(motorPin3, 0);
    analogWrite(motorPin4, 0);

}
}

Thanks in advance.

(deleted)

Hi,
These two if statements need more ( ).

if (average >= 600) && (state == 0)

Should be;

if ((average >= 600) && (state == 0))

And

else if (average <= 500) && (state == 1)

Should be;

else if ((average <= 500) && (state == 1))

When you get errors, if you look in the IDE at your code the relevant line will be highlighted.
Tom.. :slight_smile:

Hi Tom George.

Thank you very much.
I thought it would be something "silly"

That was a quick soliution....