New user need help with "error: expected declaration before '}' token" error

I am using the Tinkercad simulator to test sketch code created by another user.
I do not know enough about coding to know how to correct the error mentioned in the topic.
It occurs on the last line (#171) of the code.

The only change I made was to comment out a few instances that refer to 'Metro'(a library), so I am not sure if that is part of the problem.

I have a screenshot of the last code lines and error message.

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

Please post your full sketch and the full error message, using code tags when you do

1 Like

No way to know without the code. Probably mismatched braces.

1 Like

Thank you for the information.

Here is what I think you asked me to do:






// by John Crossen https://www.youtube.com/user/22BOZIDAR/videos
// For controlling servo coolant nozzles with sweep,tool change air blast and
// timed on/off air blast
// mapped values for potentiomers must be changed if wiring is reversed on the potentiomers
// example sweepAngle1= map(sweepAngle1,  1023,0, 0, 60); to sweepAngle1= map(sweepAngle1,  0,1023, 0, 60);
// example  if(potPin5State>1018) to  if(potPin5State<5)
#include <Servo.h>
#include <Metro.h>  //Include Metro library

Servo servo1;  // create servo object to control a servo
Servo servo2;  // create servo object to control a servo2

const int toolSwitch = 2;  // the number of the  pin for tool change switch


int potPin1 = 1;  // analog pin used to connect the potentiometer 1
int angleVal;     // variable to read the value from the analog pin 0
int potPin2 = 0;  // analog pin used to connect the potentiometer 2
int angleVal2;    // variable to read the value from the analog pin 1

int potPin3 = 3;  // analog pin used to connect the potentiometer 3
int sweepAngle1;  // variable to read the value from the analog pin 2
int potPin4 = 2;  // analog pin used to connect the potentiometer 4
int sweepAngle2;  // variable to read the value from the analog pin 3

int potPin5 = 4;  // analog pin used to connect the potentiometer 5
int airBlastOn;   // variable to read the value from the analog pin 4
int potPin6 = 5;  // analog pin used to connect the potentiometer 6
int airBlastOff;  // variable to read the value from the analog pin 5

int solenoid = 13;  // select the pin for the solenoid valve
int pos = 0;        // variable to store the tool change position for servo 1
int pos2 = 0;       // variable to store the tool change position for servo 2

int switchState1 = 0;  // variable for reading the tool change pushbutton status
int potPin5State = 0;  // variable for reading potPin5 position

int state = 0;                   //Create a variable to hold the solenoid current state
Metro solenoidMetro = Metro(0);  // Instanciate a metro object and set the interval.
int sweepDelay1;                 // variable for delay on servo1
int sweepDelay2;                 // variable for delay on servo2
void setup() {
  servo1.attach(9);   // attaches the servo on pin 9 to the servo object
  servo2.attach(10);  // attaches the servo on pin 9 to the servo object

  // initialize the switch pin as an input:
  pinMode(toolSwitch, INPUT);      // tool change switch
  digitalWrite(toolSwitch, HIGH);  // turn on internal pull up

  pinMode(solenoid, OUTPUT);  // declare the solenoidpin as an OUTPUT:
  digitalWrite(solenoid, LOW);
}

void loop() {
  // air blast and sweep to clean off tool
  switchState1 = digitalRead(toolSwitch);  //tool change switch

  if (switchState1 == HIGH)  // check if the tool change switch is pressed
  {
    delay(15);
    pos = servo1.read();  //read angle of servo1

    if (pos > 119)  // if pos is greater than 119 degree angle
    // angle must be greater than max angleVal
    {
      digitalWrite(solenoid, HIGH);  // turn on valve
      delay(500);
      servo1.write(179);  //move servo1 to 179 degree angle
      servo2.write(0);    //move servo2 to 0 degree angle
      delay(500);
      servo1.write(angleVal);   //move servo1 to start angle
      servo2.write(angleVal2);  //move servo2 to start angle
      delay(500);
      servo1.write(179);  //move servo1 to 179 degree angle
      servo2.write(0);    //move servo2 to 0 degree angle
      delay(500);
      servo1.write(angleVal);   //move servo1 to start angle
      servo2.write(angleVal2);  //move servo2 to start angle
      delay(500);
      servo1.write(179);  //move servo1 to 179 degree angle
      servo2.write(0);    //move servo2 to 0 degree angle
      delay(500);
      digitalWrite(solenoid, LOW);  // turn off solenoid valve
      servo1.write(118);            //move servo1 to 120 degree angle
      servo2.write(60);             //move servo2 to 60 degree angle
      delay(1000);
      if (pos >= 118)
        ;                           // if pos is greater than or equal to 118
      digitalWrite(solenoid, LOW);  // turn off solenoid valve
    }
  } else {
    // timed on and timed off air blast
    potPin5State = analogRead(potPin5);  //reads value of potPin5

    if (potPin5State > 1018)        // if potPin value is less than 5
      digitalWrite(solenoid, LOW);  // turn off valve

    if (potPin5State < 5)            // if potPin5 value is greater than 1018
      digitalWrite(solenoid, HIGH);  // turn on valve

    if (potPin5State > 6 && potPin5State < 1017)  // if value of potPin5 between 6 and 1017
    {
      airBlastOn = analogRead(potPin5);                // reads value from pot5
      airBlastOn = map(airBlastOn, 1023, 0, 0, 5000);  // set max on time here

      airBlastOff = analogRead(potPin6);                 //readsvalue from pot 6
      airBlastOff = map(airBlastOff, 1023, 0, 0, 5000);  // set max off time here

      if (solenoidMetro.check() == 1) {  // check if the metro has passed its interval .
        if (state == LOW) {
          state = HIGH;
          solenoidMetro.interval(airBlastOn);  // if the pin is LOW, set the interval
        } else {
          solenoidMetro.interval(airBlastOff);  // if the pin is HIGH, set the interval.
          state = LOW;
        }
        digitalWrite(solenoid, state);
      }
    }
    // angle position of coolant nozzles
    angleVal = analogRead(potPin1);               // reads the value of the potentiometer (value between 0 and 1023)
    angleVal = map(angleVal, 0, 1023, 179, 118);  // scale it to use it with the servo (value between 0 and 180)( must be less than pos value to turn off tool blast)
    servo1.write(angleVal);                       // sets the servo position according to the scaled value

    angleVal2 = analogRead(potPin2);             // reads the value of the potentiometer (value between 0 and 1023)
    angleVal2 = map(angleVal2, 1023, 0, 0, 60);  // scale it to use it with the servo (value between 0 and 180)
    servo2.write(angleVal2);                     // sets the servo position according to the scaled value

    // angle of sweep from the bottom coolant nozzle position
    sweepAngle1 = analogRead(potPin3);  // reads the value of the potentiometer (value between 0 and 1023)
    sweepAngle2 = analogRead(potPin4);  // reads the value of the potentiometer (value between 0 and 1023)

    sweepAngle1 = map(sweepAngle1, 1023, 0, 0, 60);  // scale it to use it with the servo (value between 0 and 180)
    sweepAngle2 = map(sweepAngle2, 1023, 0, 0, 60);  // scale it to use it with the servo (value between 0 and 180)

    servo1.write(angleVal + sweepAngle1);   // set angle above start  position
    servo2.write(angleVal2 - sweepAngle2);  //set angle above start  position


    sweepDelay1 = (sweepAngle1 * 5);  // sweep angle 1 multiplyed by 5
    sweepDelay2 = (sweepAngle2 * 5);  // sweep angle 2 multiplyed by 5

    if (sweepAngle1 > 0 || sweepAngle2 > 0) {  // this code is used to select the longest sweep delay
      if (sweepAngle1 >= sweepAngle2)
        delay(sweepDelay1);
      if (sweepAngle2 >= sweepAngle1)
        delay(sweepDelay2);
    }
    servo1.write(angleVal);  // return to start position of the sweep
    servo2.write(angleVal2);

    if (sweepAngle1 > 0 || sweepAngle2 > 0) {  // this code is used to select the longest sweep delay
      if (sweepAngle1 >= sweepAngle2)
        delay(sweepDelay1);
      if (sweepAngle2 >= sweepAngle1)
        delay(sweepDelay2);
    }
  }
}

The error is as shown in my first post - for the last line #171.

I doubt this was your intent:

      if (pos >= 118)
        ;                           // if pos is greater than or equal to 118
      digitalWrite(solenoid, LOW);  // turn off solenoid valve
1 Like

I am not sure why that happened as it is correct in the code I copied, but thank you for spotting it.

The IDE has a function, "copy for forum", that makes sure you get your complete code. Best to use it. When you do, just ctrl-v the code into your message, and you'll note it gets automatically placed in a code box.
Please post a new version, so we can see what you're struggling with, without doubt; I know there's more, as I only have 159 lines of code.

1 Like

I did use that function, but I think I made the mistake and uploaded a version where I had changed the 118 to 120 to match the comment, and when I changed it back I probably left that mistake. Here is the original again without that error.

// by John Crossen https://www.youtube.com/user/22BOZIDAR/videos
// For controlling servo coolant nozzles with sweep,tool change air blast and
// timed on/off air blast
// mapped values for potentiomers must be changed if wiring is reversed on the potentiomers
// example sweepAngle1= map(sweepAngle1,  1023,0, 0, 60); to sweepAngle1= map(sweepAngle1,  0,1023, 0, 60);
// example  if(potPin5State>1018) to  if(potPin5State<5)
#include <Servo.h>
#include <Metro.h>  //Include Metro library

Servo servo1;  // create servo object to control a servo
Servo servo2;  // create servo object to control a servo2

const int toolSwitch = 2;  // the number of the  pin for tool change switch


int potPin1 = 1;  // analog pin used to connect the potentiometer 1
int angleVal;     // variable to read the value from the analog pin 0
int potPin2 = 0;  // analog pin used to connect the potentiometer 2
int angleVal2;    // variable to read the value from the analog pin 1

int potPin3 = 3;  // analog pin used to connect the potentiometer 3
int sweepAngle1;  // variable to read the value from the analog pin 2
int potPin4 = 2;  // analog pin used to connect the potentiometer 4
int sweepAngle2;  // variable to read the value from the analog pin 3

int potPin5 = 4;  // analog pin used to connect the potentiometer 5
int airBlastOn;   // variable to read the value from the analog pin 4
int potPin6 = 5;  // analog pin used to connect the potentiometer 6
int airBlastOff;  // variable to read the value from the analog pin 5

int solenoid = 13;  // select the pin for the solenoid valve
int pos = 0;        // variable to store the tool change position for servo 1
int pos2 = 0;       // variable to store the tool change position for servo 2

int switchState1 = 0;  // variable for reading the tool change pushbutton status
int potPin5State = 0;  // variable for reading potPin5 position

int state = 0;                   //Create a variable to hold the solenoid current state
Metro solenoidMetro = Metro(0);  // Instanciate a metro object and set the interval.
int sweepDelay1;                 // variable for delay on servo1
int sweepDelay2;                 // variable for delay on servo2
void setup() {
  servo1.attach(9);   // attaches the servo on pin 9 to the servo object
  servo2.attach(10);  // attaches the servo on pin 9 to the servo object

  // initialize the switch pin as an input:
  pinMode(toolSwitch, INPUT);      // tool change switch
  digitalWrite(toolSwitch, HIGH);  // turn on internal pull up

  pinMode(solenoid, OUTPUT);  // declare the solenoidpin as an OUTPUT:
  digitalWrite(solenoid, LOW);
}

void loop() {
  // air blast and sweep to clean off tool
  switchState1 = digitalRead(toolSwitch);  //tool change switch

  if (switchState1 == HIGH)  // check if the tool change switch is pressed
  {
    delay(15);
    pos = servo1.read();  //read angle of servo1

    if (pos > 119)  // if pos is greater than 119 degree angle
    // angle must be greater than max angleVal
    {
      digitalWrite(solenoid, HIGH);  // turn on valve
      delay(500);
      servo1.write(179);  //move servo1 to 179 degree angle
      servo2.write(0);    //move servo2 to 0 degree angle
      delay(500);
      servo1.write(angleVal);   //move servo1 to start angle
      servo2.write(angleVal2);  //move servo2 to start angle
      delay(500);
      servo1.write(179);  //move servo1 to 179 degree angle
      servo2.write(0);    //move servo2 to 0 degree angle
      delay(500);
      servo1.write(angleVal);   //move servo1 to start angle
      servo2.write(angleVal2);  //move servo2 to start angle
      delay(500);
      servo1.write(179);  //move servo1 to 179 degree angle
      servo2.write(0);    //move servo2 to 0 degree angle
      delay(500);
      digitalWrite(solenoid, LOW);  // turn off solenoid valve
      servo1.write(118);            //move servo1 to 120 degree angle
      servo2.write(60);             //move servo2 to 60 degree angle
      delay(1000);
      if (pos >= 118);
                                   // if pos is greater than or equal to 118
      digitalWrite(solenoid, LOW);  // turn off solenoid valve
    }
  } else {
    // timed on and timed off air blast
    potPin5State = analogRead(potPin5);  //reads value of potPin5

    if (potPin5State > 1018)        // if potPin value is less than 5
      digitalWrite(solenoid, LOW);  // turn off valve

    if (potPin5State < 5)            // if potPin5 value is greater than 1018
      digitalWrite(solenoid, HIGH);  // turn on valve

    if (potPin5State > 6 && potPin5State < 1017)  // if value of potPin5 between 6 and 1017
    {
      airBlastOn = analogRead(potPin5);                // reads value from pot5
      airBlastOn = map(airBlastOn, 1023, 0, 0, 5000);  // set max on time here

      airBlastOff = analogRead(potPin6);                 //readsvalue from pot 6
      airBlastOff = map(airBlastOff, 1023, 0, 0, 5000);  // set max off time here

      if (solenoidMetro.check() == 1) {  // check if the metro has passed its interval .
        if (state == LOW) {
          state = HIGH;
          solenoidMetro.interval(airBlastOn);  // if the pin is LOW, set the interval
        } else {
          solenoidMetro.interval(airBlastOff);  // if the pin is HIGH, set the interval.
          state = LOW;
        }
        digitalWrite(solenoid, state);
      }
    }
    // angle position of coolant nozzles
    angleVal = analogRead(potPin1);               // reads the value of the potentiometer (value between 0 and 1023)
    angleVal = map(angleVal, 0, 1023, 179, 118);  // scale it to use it with the servo (value between 0 and 180)( must be less than pos value to turn off tool blast)
    servo1.write(angleVal);                       // sets the servo position according to the scaled value

    angleVal2 = analogRead(potPin2);             // reads the value of the potentiometer (value between 0 and 1023)
    angleVal2 = map(angleVal2, 1023, 0, 0, 60);  // scale it to use it with the servo (value between 0 and 180)
    servo2.write(angleVal2);                     // sets the servo position according to the scaled value

    // angle of sweep from the bottom coolant nozzle position
    sweepAngle1 = analogRead(potPin3);  // reads the value of the potentiometer (value between 0 and 1023)
    sweepAngle2 = analogRead(potPin4);  // reads the value of the potentiometer (value between 0 and 1023)

    sweepAngle1 = map(sweepAngle1, 1023, 0, 0, 60);  // scale it to use it with the servo (value between 0 and 180)
    sweepAngle2 = map(sweepAngle2, 1023, 0, 0, 60);  // scale it to use it with the servo (value between 0 and 180)

    servo1.write(angleVal + sweepAngle1);   // set angle above start  position
    servo2.write(angleVal2 - sweepAngle2);  //set angle above start  position


    sweepDelay1 = (sweepAngle1 * 5);  // sweep angle 1 multiplyed by 5
    sweepDelay2 = (sweepAngle2 * 5);  // sweep angle 2 multiplyed by 5

    if (sweepAngle1 > 0 || sweepAngle2 > 0) {  // this code is used to select the longest sweep delay
      if (sweepAngle1 >= sweepAngle2)
        delay(sweepDelay1);
      if (sweepAngle2 >= sweepAngle1)
        delay(sweepDelay2);
    }
    servo1.write(angleVal);  // return to start position of the sweep
    servo2.write(angleVal2);

    if (sweepAngle1 > 0 || sweepAngle2 > 0) {  // this code is used to select the longest sweep delay
      if (sweepAngle1 >= sweepAngle2)
        delay(sweepDelay1);
      if (sweepAngle2 >= sweepAngle1)
        delay(sweepDelay2);
    }
  }
}

I just spent some time modifying the code again by removing the functionality I do not need/want, and again I get the same error and again on the last line.

Not really relevant, but your potpin ranges are disjoint. By that I mean, your logic doesn't cover all possible values.

Thank you. I will need to experiment with the code to see exactly what impact changing this will have.

Another irrelevancy, but
This is still incorrect:

if (pos >= 118);
      // if pos is greater than or equal to 118
      digitalWrite(solenoid, LOW);  // turn off solenoid valve

and is probably meant to be "less than or equal to", reading the code.

I started making random changes, and found that when I removed the 3rd from last bracket the simulation worked. This again after I commented out 5 lines that referenced 'Metro'.

I tried to load the Metro.h library code directly into the Tinkercad simulator following an online resource, but I didn't get it to work. That is why I removed any 'Metro' lines.

I have no idea what Metro refers to, and can't compile your posted code because I don't have it(Metro.h). However, unless the error is within that code, I have yet to find the problem.

Thank you for taking the time to help. I may not activate the solenoids the way they are programed in this sketch, but if I do I will make the change you suggest.

FWIW, I did comment out all metro references (except the one within the if clause, I just changed that to "1==1", and it now compiles, so there's something related to Metro.h that's going off the rails.

I will do some digging and see if I can determine the reason.
For your interest, here is what the code is for - Programmed coolant nozzles

I will be building something similar, but with just one nozzle for MQL mist cooling, not two flood cooling/air nozzles.

[quote="tmtoronto, post:8, topic:1166633"] I get the same error [/quote]

You can not get the same error. Your current code is only 159 lines long. The original error pointed to line 171.

Please, post newest code and newest error. Thank you.

I think your simulator is not giving the right error. If you include Metro.h and Metro.cpp in your IDE, compiling completes. Without the .CPP, the compiler is very unhappy.

Try the .H and .CPP on this Metro...
https://codebender.cc/library/Metro

1 Like

I appreciate the help and suggestion. I did try to include both those files directly as instructed by an online tutorial, but will try again using the files in your link. I have not tried it yet with my actual Arduino connected, just the Tinkercad simulator, which was what gave the error.

Thank you again.

I tried a few times after copying and pasting Metro.h and Metro.cpp into the original sketch but I keep getting a "fatal error: Metro.h: No such file or directory".

Here is the modified code:



// by John Crossen https://www.youtube.com/user/22BOZIDAR/videos
// For controlling servo coolant nozzles with sweep,tool change air blast and
// timed on/off air blast
// mapped values for potentiomers must be changed if wiring is reversed on the potentiomers
// example sweepAngle1= map(sweepAngle1,  1023,0, 0, 60); to sweepAngle1= map(sweepAngle1,  0,1023, 0, 60);
// example  if(potPin5State>1018) to  if(potPin5State<5)
#include <Servo.h>

//#include <Metro.h>  //Include Metro library


#ifndef Metro_h
#define Metro_h

#include <inttypes.h>

class Metro {

public:
  Metro(unsigned long interval_millis);
  Metro(unsigned long interval_millis, uint8_t autoreset);
  void interval(unsigned long interval_millis);
  char check();
  void reset();

private:
  uint8_t autoreset;
  unsigned long previous_millis, interval_millis;
};

#endif



#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include "Metro.h"


Metro::Metro(unsigned long interval_millis) {
  this->autoreset = 0;
  interval(interval_millis);
  reset();
}

// New creator so I can use either the original check behavior or benjamin.soelberg's
// suggested one (see below).
// autoreset = 0 is benjamin.soelberg's check behavior
// autoreset != 0 is the original behavior

Metro::Metro(unsigned long interval_millis, uint8_t autoreset) {
  this->autoreset = autoreset;  // Fix by Paul Bouchier
  interval(interval_millis);
  reset();
}

void Metro::interval(unsigned long interval_millis) {
  this->interval_millis = interval_millis;
}

// Benjamin.soelberg's check behavior:
// When a check is true, add the interval to the internal counter.
// This should guarantee a better overall stability.

// Original check behavior:
// When a check is true, add the interval to the current millis() counter.
// This method can add a certain offset over time.

char Metro::check() {
  if (millis() - this->previous_millis >= this->interval_millis) {
    // As suggested by benjamin.soelberg@gmail.com, the following line
    // this->previous_millis = millis();
    // was changed to
    // this->previous_millis += this->interval_millis;

    // If the interval is set to 0 we revert to the original behavior
    if (this->interval_millis <= 0 || this->autoreset) {
      this->previous_millis = millis();
    } else {
      this->previous_millis += this->interval_millis;
    }

    return 1;
  }



  return 0;
}

void Metro::reset() {

  this->previous_millis = millis();
}

Servo servo1;  // create servo object to control a servo
Servo servo2;  // create servo object to control a servo2

const int toolSwitch = 2;  // the number of the  pin for tool change switch


int potPin1 = 1;  // analog pin used to connect the potentiometer 1
int angleVal;     // variable to read the value from the analog pin 0
int potPin2 = 0;  // analog pin used to connect the potentiometer 2
int angleVal2;    // variable to read the value from the analog pin 1

int potPin3 = 3;  // analog pin used to connect the potentiometer 3
int sweepAngle1;  // variable to read the value from the analog pin 2
int potPin4 = 2;  // analog pin used to connect the potentiometer 4
int sweepAngle2;  // variable to read the value from the analog pin 3

int potPin5 = 4;  // analog pin used to connect the potentiometer 5
int airBlastOn;   // variable to read the value from the analog pin 4
int potPin6 = 5;  // analog pin used to connect the potentiometer 6
int airBlastOff;  // variable to read the value from the analog pin 5

int solenoid = 13;  // select the pin for the solenoid valve
int pos = 0;        // variable to store the tool change position for servo 1
int pos2 = 0;       // variable to store the tool change position for servo 2

int switchState1 = 0;  // variable for reading the tool change pushbutton status
int potPin5State = 0;  // variable for reading potPin5 position

int state = 0;                   //Create a variable to hold the solenoid current state
Metro solenoidMetro = Metro(0);  // Instanciate a metro object and set the interval.
int sweepDelay1;                 // variable for delay on servo1
int sweepDelay2;                 // variable for delay on servo2
void setup() {
  servo1.attach(9);   // attaches the servo on pin 9 to the servo object
  servo2.attach(10);  // attaches the servo on pin 9 to the servo object

  // initialize the switch pin as an input:
  pinMode(toolSwitch, INPUT);      // tool change switch
  digitalWrite(toolSwitch, HIGH);  // turn on internal pull up

  pinMode(solenoid, OUTPUT);  // declare the solenoidpin as an OUTPUT:
  digitalWrite(solenoid, LOW);
}

void loop() {
  // air blast and sweep to clean off tool
  switchState1 = digitalRead(toolSwitch);  //tool change switch

  if (switchState1 == HIGH)  // check if the tool change switch is pressed
  {
    delay(15);
    pos = servo1.read();  //read angle of servo1

    if (pos > 119)  // if pos is greater than 119 degree angle
    // angle must be greater than max angleVal
    {
      digitalWrite(solenoid, HIGH);  // turn on valve
      delay(500);
      servo1.write(179);  //move servo1 to 179 degree angle
      servo2.write(0);    //move servo2 to 0 degree angle
      delay(500);
      servo1.write(angleVal);   //move servo1 to start angle
      servo2.write(angleVal2);  //move servo2 to start angle
      delay(500);
      servo1.write(179);  //move servo1 to 179 degree angle
      servo2.write(0);    //move servo2 to 0 degree angle
      delay(500);
      servo1.write(angleVal);   //move servo1 to start angle
      servo2.write(angleVal2);  //move servo2 to start angle
      delay(500);
      servo1.write(179);  //move servo1 to 179 degree angle
      servo2.write(0);    //move servo2 to 0 degree angle
      delay(500);
      digitalWrite(solenoid, LOW);  // turn off solenoid valve
      servo1.write(118);            //move servo1 to 120 degree angle
      servo2.write(60);             //move servo2 to 60 degree angle
      delay(1000);
      if (pos >= 118)
        ;                           // if pos is greater than or equal to 118
      digitalWrite(solenoid, LOW);  // turn off solenoid valve
    }
  } else {
    // timed on and timed off air blast
    potPin5State = analogRead(potPin5);  //reads value of potPin5

    if (potPin5State > 1018)        // if potPin value is less than 5
      digitalWrite(solenoid, LOW);  // turn off valve

    if (potPin5State < 5)            // if potPin5 value is greater than 1018
      digitalWrite(solenoid, HIGH);  // turn on valve

    if (potPin5State > 6 && potPin5State < 1017)  // if value of potPin5 between 6 and 1017
    {
      airBlastOn = analogRead(potPin5);                // reads value from pot5
      airBlastOn = map(airBlastOn, 1023, 0, 0, 5000);  // set max on time here

      airBlastOff = analogRead(potPin6);                 //readsvalue from pot 6
      airBlastOff = map(airBlastOff, 1023, 0, 0, 5000);  // set max off time here

      if (solenoidMetro.check() == 1) {  // check if the metro has passed its interval .
        if (state == LOW) {
          state = HIGH;
          solenoidMetro.interval(airBlastOn);  // if the pin is LOW, set the interval
        } else {
          solenoidMetro.interval(airBlastOff);  // if the pin is HIGH, set the interval.
          state = LOW;
        }
        digitalWrite(solenoid, state);
      }
    }
    // angle position of coolant nozzles
    angleVal = analogRead(potPin1);               // reads the value of the potentiometer (value between 0 and 1023)
    angleVal = map(angleVal, 0, 1023, 179, 118);  // scale it to use it with the servo (value between 0 and 180)( must be less than pos value to turn off tool blast)
    servo1.write(angleVal);                       // sets the servo position according to the scaled value

    angleVal2 = analogRead(potPin2);             // reads the value of the potentiometer (value between 0 and 1023)
    angleVal2 = map(angleVal2, 1023, 0, 0, 60);  // scale it to use it with the servo (value between 0 and 180)
    servo2.write(angleVal2);                     // sets the servo position according to the scaled value

    // angle of sweep from the bottom coolant nozzle position
    sweepAngle1 = analogRead(potPin3);  // reads the value of the potentiometer (value between 0 and 1023)
    sweepAngle2 = analogRead(potPin4);  // reads the value of the potentiometer (value between 0 and 1023)

    sweepAngle1 = map(sweepAngle1, 1023, 0, 0, 60);  // scale it to use it with the servo (value between 0 and 180)
    sweepAngle2 = map(sweepAngle2, 1023, 0, 0, 60);  // scale it to use it with the servo (value between 0 and 180)

    servo1.write(angleVal + sweepAngle1);   // set angle above start  position
    servo2.write(angleVal2 - sweepAngle2);  //set angle above start  position


    sweepDelay1 = (sweepAngle1 * 5);  // sweep angle 1 multiplyed by 5
    sweepDelay2 = (sweepAngle2 * 5);  // sweep angle 2 multiplyed by 5

    if (sweepAngle1 > 0 || sweepAngle2 > 0) {  // this code is used to select the longest sweep delay
      if (sweepAngle1 >= sweepAngle2)
        delay(sweepDelay1);
      if (sweepAngle2 >= sweepAngle1)
        delay(sweepDelay2);
    }
    servo1.write(angleVal);  // return to start position of the sweep
    servo2.write(angleVal2);

    if (sweepAngle1 > 0 || sweepAngle2 > 0) {  // this code is used to select the longest sweep delay
      if (sweepAngle1 >= sweepAngle2)
        delay(sweepDelay1);
      if (sweepAngle2 >= sweepAngle1)
        delay(sweepDelay2);
    }
  }
}

@tmtoronto
You seem to have 2 things going on

  1. Error - Expected Declaration before '}' token error

  2. Error - No Such file or Directory, even though you absolutely added the library.

so, clearly you are new to this stuff as these are beginner mistakes.

Instead of telling you the answer (which i'm sure others will do anyway) and then you'll have duplicate answers , let me show you what i do .

Problem 1 - it's called "BALANCING BRACES"
so the } thing. which is called a BRACE is the issue
You've put too many or too little in

Look at this code

void setup (){}
void loop(){}
// These are Balanced Braces
//Although you will generally see the "BARE MINIMUM" sketch to look like this
void setup (){
}

void loop(){
}

This can get confusing
so instead, when starting a sketch, Start like this...

void setup ()
{

}

void loop()
{

}

See how this is much clearer and you don't need to search for the braces.
ALWAYS have them on the left side of the screen.

the problem you are having is when this happens

void setup ()
{

}

void loop()
{

}
}  // See this extra brace ?  Notice it doesn't have an opening brace

so let me show you what i would do with your code

  1. I'd make a copy of it that i can mess with

  2. I would start with the deepest level braces and remove their contents
    and when i find an opening and closing brace , i would delete them and their contents.

the idea is... if you have balanced your braces and then you delete all your code bit by bit
you will end up with the bare minimum sketch

let's see what happens when i do that to your code

  • Your Global Stuff seems ok

  • Your setup Function seems ok
    i added a few bits and pieces for clarity

void setup() 
{ //Opens void Setup
  servo1.attach(9);   // attaches the servo on pin 9 to the servo object
  servo2.attach(10);  // attaches the servo on pin 9 to the servo object

  // initialize the switch pin as an input:
  pinMode(toolSwitch, INPUT);      // tool change switch
  digitalWrite(toolSwitch, HIGH);  // turn on internal pull up

  pinMode(solenoid, OUTPUT);
  digitalWrite(solenoid, LOW);
} // Closes void Setup

THIS IS BALANCED

Now let's look at the loop Function

ERROR 1

    if (pos > 119)  // if pos is greater than 119 degree angle
    // angle must be greater than max angleVal
    {
      digitalWrite(solenoid, HIGH);  // turn on valve
      delay(500);
      servo1.write(179);  //move servo1 to 179 degree angle
      servo2.write(0);    //move servo2 to 0 degree angle
      delay(500);
      servo1.write(angleVal);   //move servo1 to start angle
      servo2.write(angleVal2);  //move servo2 to start angle
      delay(500);
      servo1.write(179);  //move servo1 to 179 degree angle
      servo2.write(0);    //move servo2 to 0 degree angle
      delay(500);
      servo1.write(angleVal);   //move servo1 to start angle
      servo2.write(angleVal2);  //move servo2 to start angle
      delay(500);
      servo1.write(179);  //move servo1 to 179 degree angle
      servo2.write(0);    //move servo2 to 0 degree angle
      delay(500);
      digitalWrite(solenoid, LOW);  // turn off solenoid valve
      servo1.write(118);            //move servo1 to 120 degree angle
      servo2.write(60);             //move servo2 to 60 degree angle
      delay(1000);
      if (pos >= 118)
        ;                           // if pos is greater than or equal to 118
      digitalWrite(solenoid, LOW);  // turn off solenoid valve
    }

THIS IS INCORRECT

      if (pos >= 118)
        ;                           // if pos is greater than or equal to 118

IT SHOULD BE LIKE THIS..

      if (pos >= 118);                        

Moving forward..
Your Loop function was reduced to this

void loop() 
{ //Opens void loop


  else 
  { Opens else 1


  } //closes else 1
}// Closes void loop

Meaning...
YOUR BRACES ARE BALANCED
it seems like you just need to fix that first issue with the semicolon

Error 2 -
when you have included a library and it still says i'ts missing
Check the installation locations.
You may think arduino is using the my documents location when in fact it's using
the AppData Location. so it may exist in the MyDocuments location but if Arduino
is looking at the AppData location and it's not there then that's why you are getting the message.