I have a problem with "... was not declared in this scope"

I can't solve this problem. I try "using namespace", but this is not a namespace problem. I try declare in scoop, but, his apparently was not declare. I try write oter forms, BUT! Did not work. This is sad... Anyone know wath is happening, the why this is happens, and know fix this?

This is my code:

#include <Servo.h>

#define numOfValsRec 5
#define digitsPerValRec 1

Servo servoThumb;
Servo servoIndex;
Servo servoMiddle;
Servo servoRing;
Servo servoPinky;

int valsRec[numOfValsRec];
int stringLength = numOfValsRec * digitsPerValRec + 1; //$00000
int counter = 0;
bool counterStart = false;
String receieveString;
String recevivedString;
receieveData();

void setup() {
  Serial.begin(9600);
  servoThumb.attach(7);
  servoIndex.attach(9);
  servoMiddle.attach(11);
  servoRing.attach(8);  
  servoPinky.attach(10);
}

void receieveData(){
  while(Serial.available())
  {
    char c = Serial.read();

    if (c=='$'){
      counterStart = true;
    }
    if (counterStart){
      if(counter < stringLength){
         receivedString = String(receivedString+c)
         counter++;
      }
      if(counter >=stringLenght){
        for(int i = 0; i<numOfValsRec; i++){
          int num = (i*digitsPerValRec)+1;
          valsRec[0] = receivedString.substring(num,num + digitsPerValRec).toInt(); 
        }
        reivedString = "";
        counter = 0;
        counterStart = false;
      }
    }
  }
  
}

void loop() {
  
  receieveData();
  if (valsRec [0] == 1){servoThumb.write(180);}else{(servoThumb.write(0));}
  if (valsRec [1] == 1){servoIndex.write(180);}else{(servoIndex.write(0));}
  if (valsRec [2] == 1){servoMiddle.write(180);}else{(servoMiddle.write(0));}
  if (valsRec [3] == 1){servoRing.write(180);}else{(servoRing.write(0));}
  if (valsRec [4] == 1){servoPinky.write(180);}else{(servoPinky.write(0));}

}

This is the ERROR:


Arduino: 1.8.19 (Windows Store 1.8.57.0) (Windows 10), Placa:"Arduino Uno"

C:\Users\User\OneDrive\Documents\Arduino\Roboct_Arm-Fingers_Counter\Roboct_Arm-Fingers_Counter.ino: In function 'void setup()':

Roboct_Arm-Fingers_Counter:38:34: error: 'reveciveString' was not declared in this scope

         recevivedString = String(reveciveString+c);

                                  ^~~~~~~~~~~~~~

C:\Users\User\OneDrive\Documents\Arduino\Roboct_Arm-Fingers_Counter\Roboct_Arm-Fingers_Counter.ino:38:34: note: suggested alternative: 'recevivedString'

         recevivedString = String(reveciveString+c);

                                  ^~~~~~~~~~~~~~

                                  recevivedString

C:\Users\User\OneDrive\Documents\Arduino\Roboct_Arm-Fingers_Counter\Roboct_Arm-Fingers_Counter.ino: In function 'void loop()':

Roboct_Arm-Fingers_Counter:58:3: error: 'receieveData' was not declared in this scope

   receieveData();

   ^~~~~~~~~~~~

Roboct_Arm-Fingers_Counter:59:7: error: 'valsRec' was not declared in this scope

   if (valsRec [0] == 1){servoThumb.write(180);}else{(servoThumb.write(0));}

       ^~~~~~~

Roboct_Arm-Fingers_Counter:60:7: error: 'valsRec' was not declared in this scope

   if (valsRec [1] == 1){servoIndex.write(180);}else{(servoIndex.write(0));}

       ^~~~~~~

Roboct_Arm-Fingers_Counter:61:7: error: 'valsRec' was not declared in this scope

   if (valsRec [2] == 1){servoMiddle.write(180);}else{(servoMiddle.write(0));}

       ^~~~~~~

Roboct_Arm-Fingers_Counter:62:7: error: 'valsRec' was not declared in this scope

   if (valsRec [3] == 1){servoRing.write(180);}else{(servoRing.write(0));}

       ^~~~~~~

Roboct_Arm-Fingers_Counter:63:7: error: 'valsRec' was not declared in this scope

   if (valsRec [4] == 1){servoPinky.write(180);}else{(servoPinky.write(0));}

       ^~~~~~~

exit status 1

'reveciveString' was not declared in this scope



Este relatório teria mais informações com
"Mostrar a saida detalhada durante a compilação"
opção pode ser ativada em "Arquivo -> Preferências"

And leastly, this is the configuration that i'm using:

You have declared e.g. valsRec inside setup(); therefore it's only know inside setup() and not in loop(). If you want to share variables between setup() and loop(), you will need to make them global (declare outside setup()). E.g. your servos are declared in the global space.

Read up on C++ scope to learn more.

Oh, sorry, i forgot to fix it, but the same error happens fixing code as you mentioned.

My forgiveness. I will fix the post.

Speeling and cAsE are important.

Look at the exact spelling of you variables.

I don't see where this function is defined

Don’t use variable names you can’t spell

Okay. I fixed this, but the error still persist

Can you help me again, please?

Post your revised sketch in a reply; do not modify your opening post.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.