'value' was not declared in this scope

I'm a begginer with programming. I'd like to know why this message appears, well, yet I initialize all my constant.
Thanks for help :slight_smile:

sketch_nov19a.ino (4.87 KB)

Here is your code, formatted:

// TRAME MIDI (cccc = canal):

// |===============MESSAGE=================|============DONNEE1============|=========DONNEE2==========|
// | 1000 cccc = note off => 128(10) | 0xxx xxxx: hauteur note | 0xxx xxxx: vélocité |
// | 1001 cccc = note on => 129(10) | 0xxx xxxx: hauteur note | 0xxx xxxx: vélocité |
// | 1110 cccc = pitch bend => 224(10) | 0000 0000: code | 0xxx xxxx: vitesse |
// | 1011 cccc = control change => 176(10) | 0xxx xxxx: numero | 0xxx xxxx: valeur |
// --------------------------------------------------------------------------------------------------
//========================
//Analog pin ZERO
int valuePinZero = 0;
int valuePinZero2 = 0;

//Analog pin ONE
int valuePinOne = 0;
int valuePinOne2 = 0;

//Analog pin TWO
int valuePinTwo = 0;
int valuePinTwo2 = 0;

//Analog pin THREE
int valuePinTHREE = 0;
int valuePinTHREE2 = 0;

//Analog pin FOUR
int valuePinFOUR = 0;
int valuePinFOUR2 = 0;

//Analog pin FIVE
int valuePinFIVE = 0;
int valuePinFIVE2 = 0;

//Analog pin SIX
int valuePinSIX = 0;
int valuePinSIX2 = 0;

//Analog pin SEVEN
int valuePinSEVEN = 0;
int valuePinSEVEN2 = 0;

//Analog pin EIGHT
int valuePinEIGHT = 0;
int valuePinEIGHT2 = 0;

//Analog pin NINE
int valuePinNINE = 0;
int valuePinNINE2 = 0;
void setup()
{
  Serial.begin(57600); // vitesse de communication
}

void loop()
{
  //controleur ZERO
  //————————
  valuePinZero = (analogRead(0) / 8); //lecture de la valeur du potentiomètre
  if (valuePinZero - valuePinZero2 >= 2 || valuePinZero2 - valuePinZero >= 2) { //si cette valeur varie de plus de 2 entre deux lectures...


    valuePinZero2 = valuePinZero; //...on actualise

    MIDI_TX(176, 75, valuePinZero); //et on envoi un message du type (CONTROLLEUR CANAL 0, NUMERO 75, VALEUR = valeur lue) ==> voir tableau
    //delay(100); //pour le debuggage
  }

  //controleur ONE
  //————————
  valuePinOne = (analogRead(1) / 8);
  if (valuePinOne - valuePinOne2 >= 2 || valuePinOne2 - valuePinOne >= 2)
  {

    valuePinOne2 = valuePinOne;

    MIDI_TX(176, 76, valuePinOne);
    //delay(100);
  }

  //controleur TWO
  //————————
  valuePinTwo = (analogRead(2) / 8);
  if (valuePinTwo - valuePinTwo2 >= 2 || valuePinTwo2 - valuePinTwo >= 2)
  {

    valuePinTwo2 = valuePinTwo;

    MIDI_TX(176, 77, valuePinTwo);
    //delay(100);
  }

  {
    //controleur THREE
    //————————
    valuePinTHREE = (analogRead(3) / 8); //lecture de la valeur du potentiomètre
    if (valuePinTHREE - valueTHREE2 >= 2 || valuePinTHREE2 - valuePinTHREE >= 2) { //si cette valeur varie de plus de 2 entre deux lectures...

      valuePinTHREE2 = valuePinTHREE; //...on actualise

      MIDI_TX(176, 77, valuePinTHREE); //et on envoi un message du type (CONTROLLEUR CANAL 0, NUMERO 75, VALEUR = valeur lue) ==> voir tableau
      //delay(100); //pour le debuggage
    }

    //controleur FOUR
    //————————
    valuePinFOUR = (analogRead(4) / 8);
    if (valuePinFOUR - valuePinFOUR2 >= 2 || valuePinFOUR2 - valuePinFOUR >= 2)
    {

      valuePinFOUR2 = valuePinFOUR;

      MIDI_TX(176, 78, valuePinFOUR);
      //delay(100);
    }

    //controleur FIVE
    //————————
    valuePinFIVE = (analogRead(5) / 8);
    if (valuePinFIVE - valuePinFIVE2 >= 2 || valuePinFIVE2 - valuePinFIVE >= 2)
    {

      valuePinFIVE2 = valuePinFIVE;

      MIDI_TX(176, 79, valuePinFIVE);
      //delay(100);
    }

    {

      //controleur SIX
      //————————
      valuePinSIX = (analogRead(6) / 8); //lecture de la valeur du potentiomètre
      if (valuePinSIX - valuePinSIX2 >= 2 || valuePinSIX2 - valuePinSIX >= 2) { //si cette valeur varie de plus de 2 entre deux lectures...


        valuePinSIX2 = valuePinSIX; //...on actualise

        MIDI_TX(176, 80, valuePinSIX); //et on envoi un message du type (CONTROLLEUR CANAL 0, NUMERO 75, VALEUR = valeur lue) ==> voir tableau
        //delay(100); //pour le debuggage
      }

      //controleur SEVEN
      //————————
      valuePinSEVEN = (analogRead(7) / 8);
      if (valuePinSEVEN - valuePinSEVEN2 >= 2 || valuePinSEVEN2 - valuePinSEVEN >= 2)
      {

        valuePinSEVEN2 = valuePinSEVEN;

        MIDI_TX(176, 81, valuePinOne);
        //delay(100);
      }

      //controleur EIGHT
      //————————
      valuePinEIGHT = (analogRead(8) / 8);
      if (valuePinEIGHT - valuePinEIGHT2 >= 2 || valuePinEIGHT2 - valuePinEIGHT >= 2)
      {

        valuePinEIGHT2 = valuePinEIGHT;

        MIDI_TX(176, 82, valuePinEIGHT);
        //delay(100);
      }

      {
        //controleur NINE
        //————————
        valuePinNINE = (analogRead(9) / 8); //lecture de la valeur du potentiomètre
        if (valuePinNINE - valuePinNINE2 >= 2 || valuePinNINE2 - valuePinNINE >= 2) { //si cette valeur varie de plus de 2 entre deux lectures...


          valueNINE = valuePinNINE; //...on actualise

          MIDI_TX(176, 83, valuePinNINE); //et on envoi un message du type (CONTROLLEUR CANAL 0, NUMERO 75, VALEUR = valeur lue) ==> voir tableau
          //delay(100);//pour le debuggage
          {


          }

          void MIDI_TX(unsigned char MESSAGE, unsigned char DONNEE1, unsigned char DONNEE2) //fonction d'envoi du message MIDI ==> voir tableau
          {
            Serial.write(MESSAGE); //envoi de l'octet de message sur le port série
            Serial.write(DONNEE1); //envoi de l'octet de donnée 1 sur le port série
            Serial.write(DONNEE2); //envoi de l'octet de donnée 2 sur le port série
          }

Errors:

sketch_nov23a.ino: In function 'void loop()':
sketch_nov23a.ino:96:19: error: 'valueTHREE2' was not declared in this scope
sketch_nov23a.ino:173:1: error: 'valueNINE' was not declared in this scope
sketch_nov23a.ino:183:1: error: a function-definition is not allowed here before '{' token
sketch_nov23a.ino:187:1: error: expected '}' at end of input
sketch_nov23a.ino:187:1: error: expected '}' at end of input
sketch_nov23a.ino:187:1: error: expected '}' at end of input
sketch_nov23a.ino:187:1: error: expected '}' at end of input
sketch_nov23a.ino:187:1: error: expected '}' at end of input
'valueTHREE2' was not declared in this scope

Now closely compare the error messages to your code. valueTHREE2 is indeed not declared.

Your use of braces is rather weird. Don't just throw them in for no reason.

Thank you! But no I have this error: Arduino: 1.6.4 (Windows 7), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

sketch_nov19a.ino: In function 'void loop()':
sketch_nov19a:64: error: 'MIDI_TX' was not declared in this scope
sketch_nov19a:76: error: 'MIDI_TX' was not declared in this scope
sketch_nov19a:88: error: 'MIDI_TX' was not declared in this scope
sketch_nov19a:100: error: 'MIDI_TX' was not declared in this scope
sketch_nov19a:112: error: 'MIDI_TX' was not declared in this scope
sketch_nov19a:124: error: 'MIDI_TX' was not declared in this scope
sketch_nov19a:138: error: 'MIDI_TX' was not declared in this scope
sketch_nov19a:150: error: 'MIDI_TX' was not declared in this scope
sketch_nov19a:162: error: 'MIDI_TX' was not declared in this scope
sketch_nov19a:175: error: 'MIDI_TX' was not declared in this scope
sketch_nov19a:183: error: expected initializer before '}' token
sketch_nov19a:185: error: 'MESSAGE' was not declared in this scope
sketch_nov19a:186: error: 'DONNEE1' was not declared in this scope
sketch_nov19a:187: error: 'DONNEE2' was not declared in this scope
'MIDI_TX' was not declared in this scope

Hint: we can't see your revised code.
Please use code tags .

there's the code:

sketch_nov19a.ino (5.39 KB)

You either clipped off the bottom of your code, or you have tons of unmatched curly-braces {}

It looks like you're putting opening curly-braces where you don't need them - and not putting matching ones in either.

You can even see in the indentation, that you've got like 4 open blocks at the bottom of your code...

If you removed the unnecessary opening braces, you'd still be... I think two closing braces short?

Every opening curly-brace must be matched with a closing curly-brace.

Done! thanks so much for all!
there's the final code:

final_analogin.ino (5.4 KB)

can anyone help me this is my code but with many faults this are the faults

\Untitled2.ino: In function 'void loop()':

Untitled2:109: error: 'Pin3' was not declared in this scope

int pin3 = map(analogRead(Pin3), 74, 1000, 0, 255);
^
Untitled2:111: error: 'Pin5' was not declared in this scope

int pin5 = map(analogRead(Pin5), 76, 1000, 0, 255); ^

Untitled2:113: error: 'Pin7' was not declared in this scope

int pin7 = map(analogRead(Pin7), 78, 1000, 0, 255);

^

Untitled2:115: error: 'Pin9' was not declared in this scope

int pin9 = map(analogRead(Pin9), 80, 1000, 0, 255);
^
Untitled2:116: error: 'Pin10' was not declared in this scope

int pin10 = map(analogRead(Pin10), 81, 1000, 0, 255);

Untitled2:118: error: 'Pin12' was not declared in this scope

int pin12 = map(analogRead(Pin12), 83, 1000, 0, 255);

Untitled2:120: error: 'Pin14' was not declared in this scope

int pin14 = map(analogRead(Pin14), 85, 1000, 0, 255);

Untitled2:121: error: 'Pin15' was not declared in this scope

int pin15 = map(analogRead(Pin15), 86, 1000, 0, 255); ^

Untitled2:124: error: 'Joystick' was not declared in this scope

Joystick.setState(&joySt);

Untitled2:124: error: 'joySt' was not declared in this scope

Joystick.setState(&joySt);

Untitled2:125: error: 'programBtn' was not declared in this scope

if (digitalRead(programBtn) != HIGH) {

\Untitled2.ino: In function 'int GetButtonsValue()':

Untitled2:136: error: 'button1' was not declared in this scope

if (digitalRead(button1) != HIGH) {

Untitled2:137: error: 'maskBtn1' was not declared in this scope

returnVal = returnVal | maskBtn1;

Untitled2:139: error: 'button2' was not declared in this scope

if (digitalRead(button2) != HIGH) {

Untitled2:140: error: 'maskBtn2' was not declared in this scope

returnVal = returnVal | maskBtn2;

^

Untitled2:142: error: 'button3' was not declared in this scope

if (digitalRead(button3) != HIGH) {

Untitled2:143: error: 'maskBtn3' was not declared in this scope

returnVal = returnVal | maskBtn3;

Untitled2:145: error: 'button4' was not declared in this scope

if (digitalRead(button4) != HIGH) {

Untitled2:146: error: 'maskBtn4' was not declared in this scope

returnVal = returnVal | maskBtn4;

^

Untitled2:148: error: 'button5' was not declared in this scope

if (digitalRead(button5) != HIGH) {

Untitled2:149: error: 'maskBtn5' was not declared in this scope

returnVal = returnVal | maskBtn5;

Untitled2:151: error: 'button6' was not declared in this scope

if (digitalRead(button6) != HIGH) {

^

Untitled2:152: error: 'maskBtn6' was not declared in this scope

returnVal = returnVal | maskBtn6;

Untitled2:154: error: 'button7' was not declared in this scope

if (digitalRead(button7) != HIGH) {

Untitled2:155: error: 'maskBtn7' was not declared in this scope

returnVal = returnVal | maskBtn7;

Untitled2:157: error: 'button8' was not declared in this scope

if (digitalRead(button8) != HIGH) {

Untitled2:158: error: 'maskBtn8' was not declared in this scope

returnVal = returnVal | maskBtn8;

Untitled2:160: error: 'button9' was not declared in this scope

if (digitalRead(button9) != HIGH) {

Untitled2:161: error: 'maskBtn9' was not declared in this scope
^

exit status 1
'Pin3' was not declared in this scope

this is the code:

// Arduino usb controller

void setup()

{
pinMode(13, OUTPUT);

// specify the digital pin number for each button
const int button1 = 2;
const int button2 = 4;
const int button3 = 6;
const int button4 = 8;
const int button5 = 10;
const int button6 = 12;
const int button7 = 14;
const int button8 = 16;
const int button9 = 18;
const int button10 =20;
const int button11 =22;
const int button12 =24;
const int button13 =26;
const int button14 =28;
const int button15 =30;
const int button16 =32;
const int button17 =34;
const int button18 =36;

// mask value for each button
const int maskBtn1 = 2;
const int maskBtn2 = 4;
const int maskBtn3 = 6;
const int maskBtn4 = 8;
const int maskBtn5 = 10;
const int maskBtn6 = 12;
const int maskBtn7 = 14;
const int maskBtn8 = 16;
const int maskBtn9 = 18;
const int maskBtn10 = 20;
const int maskBtn11 = 22;
const int maskBtn12 = 24;
const int maskBtn13 = 26;
const int maskBtn14 = 28;
const int maskBtn15 = 30;
const int maskBtn16 = 32;
const int maskBtn17 = 34;
const int maskBtn18 = 36;

// specify analog pin number for each pot

const int pin0 = A0;
const int pin1 = A1;
const int pin2 = A2;
const int pin3 = A3;
const int pin4 = A4;
const int pin5 = A5;
const int Pin6 = A6;
const int pin7 = A7;
const int Pin8 = A8;
const int pin9 = A9;
const int pin10 = A10;
const int pin11 = A11;
const int pin12 = A12;
const int Pin13 = A13;
const int pin14 = A14;
const int pin15 = A15;

// special button used to temporarily
// suspend the flow of key and mouse data
// when pushing a sketch to the Arduino
const int programBtn = 19;

// initialize serial communication at 9600 bits per second
// The Leonardo board uses Serial1 to communicate via TTL (5V) serial on pins 0 (RX) and 1 (TX)
Serial.begin(9600);

// set button pins as input with pullup enabled
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(button3, INPUT_PULLUP);
pinMode(button4, INPUT_PULLUP);
pinMode(button5, INPUT_PULLUP);
pinMode(button6, INPUT_PULLUP);
pinMode(button7, INPUT_PULLUP);
pinMode(button8, INPUT_PULLUP);
pinMode(button9, INPUT_PULLUP);
pinMode(button10, INPUT_PULLUP);
pinMode(button11, INPUT_PULLUP);
pinMode(button12, INPUT_PULLUP);
pinMode(button13, INPUT_PULLUP);
pinMode(button14, INPUT_PULLUP);
pinMode(button15, INPUT_PULLUP);
pinMode(button16, INPUT_PULLUP);
pinMode(button17, INPUT_PULLUP);
pinMode(button18, INPUT_PULLUP);
pinMode(programBtn, INPUT_PULLUP);
}

void loop() {

// Windows sees our controller as a Joystick
int pin0 = map(analogRead(pin0), 71, 1000, 0, 255);
int pin1 = map(analogRead(pin1), 72, 1000, 0, 255);
int pin2 = map(analogRead(pin2), 73, 1000, 0, 255);
int pin3 = map(analogRead(Pin3), 74, 1000, 0, 255);
int pin4 = map(analogRead(pin4), 75, 1000, 0, 255);
int pin5 = map(analogRead(Pin5), 76, 1000, 0, 255);
int pin6 = map(analogRead(pin6), 77, 1000, 0, 255);
int pin7 = map(analogRead(Pin7), 78, 1000, 0, 255);
int pin8 = map(analogRead(pin8), 79, 1000, 0, 255);
int pin9 = map(analogRead(Pin9), 80, 1000, 0, 255);
int pin10 = map(analogRead(Pin10), 81, 1000, 0, 255);
int pin11 = map(analogRead(pin11), 82, 1000, 0, 255);
int pin12 = map(analogRead(Pin12), 83, 1000, 0, 255);
int pin13 = map(analogRead(pin13), 84, 1000, 0, 255);
int pin14 = map(analogRead(Pin14), 85, 1000, 0, 255);
int pin15 = map(analogRead(Pin15), 86, 1000, 0, 255);

// finally, we send the "Joystick" data to the PC
Joystick.setState(&joySt);
if (digitalRead(programBtn) != HIGH) {
// if the program button is pushed, we slow the loop.
// This lets us push code to the Arduino
delay(250);
}
}

// check each button, if currently pushed "OR"
// that button's mask value with the return value
int GetButtonsValue(){
int returnVal = 0;
if (digitalRead(button1) != HIGH) {
returnVal = returnVal | maskBtn1;
}
if (digitalRead(button2) != HIGH) {
returnVal = returnVal | maskBtn2;
}
if (digitalRead(button3) != HIGH) {
returnVal = returnVal | maskBtn3;
}
if (digitalRead(button4) != HIGH) {
returnVal = returnVal | maskBtn4;
}
if (digitalRead(button5) != HIGH) {
returnVal = returnVal | maskBtn5;
}
if (digitalRead(button6) != HIGH) {
returnVal = returnVal | maskBtn6;
}
if (digitalRead(button7) != HIGH) {
returnVal = returnVal | maskBtn7;
}
if (digitalRead(button8) != HIGH) {
returnVal = returnVal | maskBtn8;
}
if (digitalRead(button9) != HIGH) {
returnVal = returnVal | maskBtn9;
}
if (digitalRead(button10) != HIGH) {
returnVal = returnVal | maskBtn10;
}
if (digitalRead(button11) != HIGH) {
returnVal = returnVal | maskBtn11;
}
if (digitalRead(button12) != HIGH) {
returnVal = returnVal | maskBtn12;
}
if (digitalRead(button13) != HIGH) {
returnVal = returnVal | maskBtn13;
}
if (digitalRead(button14) != HIGH) {
returnVal = returnVal | maskBtn14;
}
if (digitalRead(button15) != HIGH) {
returnVal = returnVal | maskBtn15;
}
if (digitalRead(button16) != HIGH) {
returnVal = returnVal | maskBtn16;
}
if (digitalRead(button17) != HIGH) {
returnVal = returnVal | maskBtn17;
}
if (digitalRead(button18) != HIGH) {
returnVal = returnVal | maskBtn18;
}
// returnVal represents
return returnVal;
}

Untitled2.ino (5.04 KB)

error: 'Pin3' was not declared in this scopeNo surprise there - there is no variable called "Pin3" in the code you posted, badly.

Look up "Variable Scope". https://www.arduino.cc/reference/en/language/variables/variable-scope--qualifiers/scope/

You have declared everything inside setup(). That means the things you've declared can only be used in setup().

Then you try to use them in loop(). Naturally you get errors.

BTW C++ is case sensitive so Pin1 and pin1 are NOT the same. Declaring yours pins as pin5, Pin6, pin7 and Pin8 is bound to confuse you...and the compiler.

Steve