'calibrateFader' was not declared in this scope

Hello Arduino comunity! I want to make a midi controlled motorized fader, I find a code on internet for it but it have some issues…
There are the errors:

Motorized_Fader:67:17: error: expected constructor, destructor, or type conversion before ‘(’ token

Motorized_Fader:68:17: error: expected constructor, destructor, or type conversion before ‘(’ token

Motorized_Fader:69:1: error: expected declaration before ‘}’ token

exit status 1
‘calibrateFader’ was not declared in this scope

I not just want you guys to fixe the code, I want to understand this error first of all.
I hope you guys can help me!!!

Motorized_Fader.ino (6.75 KB)

void setup()
{
   MIDI.begin(MIDI_CHANNEL_OMNI); //Receive messages on all MIDI channels
   MIDI.turnThruOff(); //We don't need MIDI through for this

   pinMode (motorUp, OUTPUT);
   pinMode (motorDown, OUTPUT);

   calibrateFader();
   //}  // stray }
   attachInterrupt(0, nextChannel, RISING);
   attachInterrupt(1, prevChannel, RISING);
}

The stray curly bracket put the attachInterrupts outside of any function.
I can't compile the code. Missing libraries.

/* -----------------------------------------------------------------------
* Copyright © 2016. Guerau Pasola, Adrian Salvador
* We only updated the code to make it work on 2016, library dependencies
* have changed their API since 2012, all credits for the code goes to:
* Copyright © 2012. Cody Hazelwood.
* -----------------------------------------------------------------------
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* -----------------------------------------------------------------------
* Platform: Arduino Uno
* Description: MIDI controller using a motorized fader and an Arduino
* Dependencies: Capacitive Sensor Arduino Library (for fader touch sensitivity)
* http://playground.arduino.cc/Main/CapacitiveSensor
* MIDI Library for Arduino
* http://www.arduino.cc/playground/Main/MIDILibrary
* -----------------------------------------------------------------------
*/
/************************************************************************
 * Currently known issues:
 *
 * * Only DAW Channels 1-8 work right now
 * * Better Fader Calibration is needed
 * * Doesn't work with Pro Tools due to Avid's restrictions (but any
 * other DAW that supports Mackie Control without HUI support will
 * work fine (Cubase, Logic, Digital Performer, Live, etc.)
 *
 *************************************************************************/

#include <CapacitiveSensor.h> //Library for fader touch sensitivity
#include <MIDI.h> //Library for receiving MIDI messages
MIDI_CREATE_DEFAULT_INSTANCE();
#define PitchBend 0xE0
//Arduino Pin Assignments
const int motorDown = 5; //H-Bridge control to make the motor go down
const int motorUp = 6; //H-Bridge control to make the motor go up
//Inputs
const int wiper = 0; //Position of fader relative to GND (Analog 0)
const int touchSend = 7; //Send pin for Capacitance Sensing Circuit (Digital 7)
const int touchReceive = 8; //Receive pin for Capacitance Sensing Circuit (Digital 8)
//Variables
double faderMax = 0; //Value read by fader's maximum position (0-1023)
double faderMin = 0; //Value read by fader's minimum position (0-1023)
int faderChannel = 1; //Value from 1-8
bool touched = false; //Is the fader currently being touched?
bool positionUpdated = false; //Since touching, has the MIDI position been updated?
CapacitiveSensor touchLine = CapacitiveSensor(touchSend, touchReceive);

void setup() {
 MIDI.begin(MIDI_CHANNEL_OMNI); //Receive messages on all MIDI channels
 MIDI.turnThruOff(); //We don't need MIDI through for this

 pinMode (motorUp, OUTPUT);
 pinMode (motorDown, OUTPUT);

 calibrateFader();
 }
 attachInterrupt(0, nextChannel, RISING);
 attachInterrupt(1, prevChannel, RISING);
}
void loop() {
 /* If there is a MIDI message waiting, and it is for the currently selected
 fader, and it is a PitchBend message (used for fader control), then convert
 the PitchBend value and update the fader's current position. */
 if (MIDI.read() && MIDI.getChannel() == faderChannel && MIDI.getType() == PitchBend ) {
 /* Bitwise math to take two 7 bit values for the PitchBend and convert to
 a single 14 bit value. Then converts it to value between 0 and 1023
 to control the fader. */

 int value = (((MIDI.getData2() << 7) + MIDI.getData1()) * 0.0625);
 updateFader(value);
 }

 checkTouch(); //Checks to see if the fader is being touched

 //If the fader has been touched, it needs to update the position on the MIDI host
 if (!positionUpdated) {
 updateFaderMidi();
 positionUpdated = true;
 }
}
void updateFaderMidi() {
 int velocity = faderPosition();
 byte channelData = 0xE0 + (faderChannel - 1);
 // MIDI Message:
 Serial.write(channelData); // E(PitchBend) Channel (0-9)
 Serial.write(velocity & 0x7F); // Least Sig Bits of Data
 Serial.write((velocity >> 7) & 0x7F); // Most Sig Bits of Data
//Check to see if the fader is being touched
void checkTouch() {
 //For the capacitiveSensor comparison below,
 //700 is arbitrary and may need to be changed
 //depending on the fader cap used (if any).
 if (!touched && touchLine.capacitiveSensor(30) >= 700) {
 touched = true;

 //Send MIDI Touch On Message
 Serial.write(0x90);
 Serial.write(0x67 + faderChannel);
 Serial.write(0x7f);
 }
 else if (touched && touchLine.capacitiveSensor(30) < 700) {
 touched = false;

 //Send MIDI Touch Off Message
 Serial.write(0x90);
 Serial.write(0x67 + faderChannel);
 Serial.write((byte) 0x00);
 }

 if (touched) {
 positionUpdated = false;
 }
}
//Function to move fader to a specific position between 0-1023 if it's not already there
void updateFader(int position) {
 if (position < analogRead(wiper) - 10 && position > faderMin && !touched) {
 digitalWrite(motorDown, HIGH);
 while (position < analogRead(wiper) - 10 && !touched) {}; //Loops until motor is done moving
 digitalWrite(motorDown, LOW);
 }
 else if (position > analogRead(wiper) + 10 && position < faderMax && !touched) {
 digitalWrite(motorUp, HIGH);
 while (position > analogRead(wiper) + 10 && !touched) {}; //Loops until motor is done moving
 digitalWrite(motorUp, LOW);
 }
}
//Selects the next channel in the DAW
void nextChannel() {
 static unsigned long last_interrupt0_time = 0; //Interrupt Debouncing
 unsigned long interrupt0_time = millis(); //Interrupt Debouncing

 if (interrupt0_time - last_interrupt0_time > 200) { //Interrupt Debouncing
 if (faderChannel < 8) {
 faderChannel++;

 Serial.write(0x90);
 Serial.write(0x17 + faderChannel);
 Serial.write(0x7f); //Note On
 Serial.write(0x90);
 Serial.write(0x17 + faderChannel);
 Serial.write((byte) 0x00); //Note Off
 }
 }

 last_interrupt0_time = interrupt0_time; //Interrupt Debouncing
}
//Selects the previous channel in the DAW
void prevChannel() {
 static unsigned long last_interrupt1_time = 0; //Interrupt Debouncing
 unsigned long interrupt1_time = millis(); //Interrupt Debouncing

 if (interrupt1_time - last_interrupt1_time > 200) { //Interrupt Debouncing
 if (faderChannel > 1) {
 faderChannel--;

 Serial.write(0x90);
 Serial.write(0x17 + faderChannel);
 Serial.write(0x7f); //Note On
 Serial.write(0x90);
 Serial.write(0x17 + faderChannel);
 Serial.write((byte) 0x00); //Note Off
 }
 }

 last_interrupt1_time = interrupt1_time; //Interrupt Debouncing
}

Thank you for the quick Reply, but i still with the exact same error problem...
It can be a Librarie Issue?

Where did you find the code?
(please don't say Instructables)
Maybe the answer is there.

I found it there:

The guy made a remake with the new libraries...

The original code from Cody Hazelwood:
https://blog.codyhazelwood.me/midi-control-with-an-arduino-and-a-motorized-fader/

I found a copy in this PDF file:

It compiled without errors or warnings.

/* -----------------------------------------------------------------------
  Copyright © 2016. Guerau Pasola, Adrian Salvador
  We only updated the code to make it work on 2016, library dependencies
  have changed their API since 2012, all credits for the code goes to:
  Copyright © 2012. Cody Hazelwood.
  -----------------------------------------------------------------------
  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.


  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  GNU General Public License for more details.


  You should have received a copy of the GNU General Public License
  along with this program. If not, see <http://www.gnu.org/licenses/>.
  -----------------------------------------------------------------------
  Platform: Arduino Uno
  Description: MIDI controller using a motorized fader and an Arduino
  Dependencies: Capacitive Sensor Arduino Library (for fader touch sensitivity)
  http://playground.arduino.cc/Main/CapacitiveSensor
  MIDI Library for Arduino
  http://www.arduino.cc/playground/Main/MIDILibrary
  -----------------------------------------------------------------------
*/
/************************************************************************
   Currently known issues:


 * * Only DAW Channels 1-8 work right now
 * * Better Fader Calibration is needed
 * * Doesn't work with Pro Tools due to Avid's restrictions (but any
   other DAW that supports Mackie Control without HUI support will
   work fine (Cubase, Logic, Digital Performer, Live, etc.)


 *************************************************************************/


#include <CapacitiveSensor.h> //Library for fader touch sensitivity
#include <MIDI.h> //Library for receiving MIDI messages
MIDI_CREATE_DEFAULT_INSTANCE();


#define PitchBend 0xE0


//Arduino Pin Assignments
const int motorDown = 5; //H-Bridge control to make the motor go down
const int motorUp = 6; //H-Bridge control to make the motor go up
//Inputs
const int wiper = 0; //Position of fader relative to GND (Analog 0)
const int touchSend = 7; //Send pin for Capacitance Sensing Circuit (Digital 7)
const int touchReceive = 8; //Receive pin for Capacitance Sensing Circuit (Digital 8)
//Variables
double faderMax = 0; //Value read by fader's maximum position (0-1023)
double faderMin = 0; //Value read by fader's minimum position (0-1023)
int faderChannel = 1; //Value from 1-8
bool touched = false; //Is the fader currently being touched?
bool positionUpdated = false; //Since touching, has the MIDI position been updated?
CapacitiveSensor touchLine = CapacitiveSensor(touchSend, touchReceive);
void setup()
{
  MIDI.begin(MIDI_CHANNEL_OMNI); //Receive messages on all MIDI channels
  MIDI.turnThruOff(); //We don't need MIDI through for this


  pinMode (motorUp, OUTPUT);
  pinMode (motorDown, OUTPUT);


  calibrateFader();
  attachInterrupt(0, nextChannel, RISING);
  attachInterrupt(1, prevChannel, RISING);
}
void loop()
{
  /* If there is a MIDI message waiting, and it is for the currently selected
    fader, and it is a PitchBend message (used for fader control), then convert
    the PitchBend value and update the fader's current position. */
  if (MIDI.read() && MIDI.getChannel() == faderChannel && MIDI.getType() == PitchBend )
  {
    /* Bitwise math to take two 7 bit values for the PitchBend and convert to
      a single 14 bit value. Then converts it to value between 0 and 1023
      to control the fader. */


    int value = (((MIDI.getData2() << 7) + MIDI.getData1()) * 0.0625);
    updateFader(value);
  }


  checkTouch(); //Checks to see if the fader is being touched


  //If the fader has been touched, it needs to update the position on the MIDI host
  if (!positionUpdated)
  {
    updateFaderMidi();
    positionUpdated = true;
  }
}
void updateFaderMidi()
{
  int velocity = faderPosition();
  byte channelData = 0xE0 + (faderChannel - 1);
  // MIDI Message:
  Serial.write(channelData); // E(PitchBend) Channel (0-9)
  Serial.write(velocity & 0x7F); // Least Sig Bits of Data
  Serial.write((velocity >> 7) & 0x7F); // Most Sig Bits of Data
}
//Calibrates the min and max position of the fader
void calibrateFader()
{
  //Send fader to the top and read max position
  digitalWrite(motorUp, HIGH);
  delay(250);
  digitalWrite(motorUp, LOW);
  faderMax = analogRead(wiper) - 5;


  //Send fader to the bottom and read min position
  digitalWrite(motorDown, HIGH);
  delay(250);
  digitalWrite(motorDown, LOW);
  faderMin = analogRead(wiper) + 5;
}
//Returns a MIDI pitch bend value for the fader's current position
//Cases ensure that there is a -infinity (min) and max value despite possible math error
int faderPosition()
{
  int position = analogRead(wiper);
  int returnValue = 0;


  if (position <= faderMin)
  {
    returnValue = 0;
  }
  else if (position >= faderMax)
  {
    returnValue = 16383;
  }
  else
  {
    returnValue = ((float)(position - faderMin) / (faderMax - faderMin)) * 16383;
  }


  return returnValue;
}
//Check to see if the fader is being touched
void checkTouch()
{
  //For the capacitiveSensor comparison below,
  //700 is arbitrary and may need to be changed
  //depending on the fader cap used (if any).
  if (!touched && touchLine.capacitiveSensor(30) >= 700)
  {
    touched = true;


    //Send MIDI Touch On Message
    Serial.write(0x90);
    Serial.write(0x67 + faderChannel);
    Serial.write(0x7f);
  }
  else if (touched && touchLine.capacitiveSensor(30) < 700)
  {
    touched = false;


    //Send MIDI Touch Off Message
    Serial.write(0x90);
    Serial.write(0x67 + faderChannel);
    Serial.write((byte) 0x00);
  }


  if (touched)
  {
    positionUpdated = false;
  }
}
//Function to move fader to a specific position between 0-1023 if it's not already there
void updateFader(int position)
{
  if (position < analogRead(wiper) - 10 && position > faderMin && !touched)
  {
    digitalWrite(motorDown, HIGH);
    while (position < analogRead(wiper) - 10 && !touched) {}; //Loops until motor is done moving
    digitalWrite(motorDown, LOW);
  }
  else if (position > analogRead(wiper) + 10 && position < faderMax && !touched)
  {
    digitalWrite(motorUp, HIGH);
    while (position > analogRead(wiper) + 10 && !touched) {}; //Loops until motor is done moving
    digitalWrite(motorUp, LOW);
  }
}


//Selects the next channel in the DAW
void nextChannel()
{
  static unsigned long last_interrupt0_time = 0; //Interrupt Debouncing
  unsigned long interrupt0_time = millis(); //Interrupt Debouncing


  if (interrupt0_time - last_interrupt0_time > 200)   //Interrupt Debouncing
  {
    if (faderChannel < 8)
    {
      faderChannel++;


      Serial.write(0x90);
      Serial.write(0x17 + faderChannel);
      Serial.write(0x7f); //Note On
      Serial.write(0x90);
      Serial.write(0x17 + faderChannel);
      Serial.write((byte) 0x00); //Note Off
    }
  }


  last_interrupt0_time = interrupt0_time; //Interrupt Debouncing
}
//Selects the previous channel in the DAW
void prevChannel()
{
  static unsigned long last_interrupt1_time = 0; //Interrupt Debouncing
  unsigned long interrupt1_time = millis(); //Interrupt Debouncing


  if (interrupt1_time - last_interrupt1_time > 200)   //Interrupt Debouncing
  {
    if (faderChannel > 1)
    {
      faderChannel--;


      Serial.write(0x90);
      Serial.write(0x17 + faderChannel);
      Serial.write(0x7f); //Note On
      Serial.write(0x90);
      Serial.write(0x17 + faderChannel);
      Serial.write((byte) 0x00); //Note Off
    }
  }


  last_interrupt1_time = interrupt1_time; //Interrupt Debouncing
}

That GitHub code has a calibrateFader function.

Post the latest code and the error. We can’t fix code that we can’t see.