Go Down

Topic: many WTF error about variable (Read 737 times) previous topic - next topic

Sinistag

Hi, it's my first real project on arduino (just make blink some LEDs before). the goal is to control an arm to carries CDs from one driver to another. i've started the code but because he's little bit long, i've try to check it before  ending it. After resolving the most classical error, the compiler tell me some error that i don't understand:
Code: [Select]
#include <Stepper.h>
#define STEPS 400
#define NOMBRE_DE_PAS 200
#define MILISEC_FOR_OPEN_DRIVER 1000

//Stepper MotorTranslation(STEPS, 50, 51, 52, 53);
Stepper MotorRotation(STEPS, 9, 10, 11, 12);

int ChoixJeux1=0;
int ChoixJeux2=1;
int ChoixJeux3=2;
int CapteurPressionCD=3;
int CapteurBrasHaut=7;
int CapteurPositionBras=8;

int data = 4;
int clock = 5;
int latch = 6;


int Lecteur = 0;

void descendre();
{
  do
  {
    digitalRead(CapteurPressionCD);
    if(CapteurPressionCD == LOW)
    {
      MotorTranslation.step(1);
    }
    delay(50);
  }while(CapteurPressionCD == LOW);
}

void setup()
{
  pinMode(ChoixJeux1, INPUT);
  pinMode(ChoixJeux2, INPUT);
  pinMode(ChoixJeux3, INPUT);
  pinMode(CapteurPressionCD, INPUT);
  pinMode(CapteurBrasHaut, INPUT);
 
  pinMode(data, OUTPUT);
  pinMode(clock, OUTPUT);
  pinMode(latch, OUTPUT);
 
  MotorRotation.setSpeed(10);
}

void loop()
{
  int JeuxChoisi=0;
  int JeuxCharge=0;
 
  Serial.begin(9600);
 
  JeuxChoisi = ReadChoixJeux();
 
  if(JeuxChoisi != 0)
  {
    do
    {
      digitalRead(CapteurBrasHaut);
      if(CapteurBrasHaut == LOW)
      {
        MotorTranslation.step(-1);
      }
      delay(50);
    }while(CapteurBrasHaut == LOW);
   
    do
    {
      digitalRead(CapteurPositionBras);
      if(CapteurPositionBras == LOW)
      {
        MotorRotation.step(-1);
      }
      delay(50);
    }while(CapteurPositionBras == LOW);
   
    switch(JeuxCharge)
    {
      case 0:
      PrendreUnJeux();
        break;
     
      case 1:
      RangerJeux(1);
      PrendreUnJeux(JeuxChoisi);
        break;
     
      case 2:
      RangerJeux(2);
      PrendreUnJeux(JeuxChoisi);
        break;
       
      case 3:
      RangerJeux(3);
      PrendreUnJeux(JeuxChoisi);
        break;
    }
  }
}

int ReadChoixJeux()
{
  int JeuxChoisi=0;
 
  digitalRead(ChoixJeux1);
  digitalRead(ChoixJeux2);
  digitalRead(ChoixJeux3);
 
  if(ChoixJeux1 == HIGH)
  {
    JeuxChoisi=1;
  }
  else if (ChoixJeux2 == HIGH)
  {
    JeuxChoisi=2;
  }
  else if (ChoixJeux3 == HIGH)
  {
    JeuxChoisi=3;
  }
  else
  {
    JeuxChoisi=0;
  }
 
  return JeuxChoisi;
}

void PrendreUnJeux(int JeuxChoisi)
{
  int puce=0;
 
  do
  {
    digitalRead(CapteurPositionBras);
    if(CapteurPositionBras == LOW)
    {
      MotorRotation.step(-1);
    }
    delay(50);
  }while(CapteurPositionBras == LOW);
 
  Lecteur = pow(2, JeuxChoisi-1);
  digitalWrite(latch, LOW);
  shiftOut(data, clock, MSBFIRST, Lecteur+puce);
  delay(MILISEC_FOR_OPEN_DRIVER);
  shiftOut(data, clock, MSBFIRST, puce);
  digitalWrite(latch, HIGH);
 
  descendre();
 
  digitalWrite(latch, LOW);
  puce = puce + 128;
  shiftOut(data, clock, MSBFIRST, puce);
  digitalWrite(latch, LOW);
 
  Monter();
 
  MotorRotation.step(NOMBRE_DE_PAS);
 
  descendre();
 
  digitalWrite(latch, LOW);
  puce = puce - 128;
  shiftOut(data, clock, MSBFIRST, puce);
  digitalWrite(latch, LOW);
 
  Monter();
 
  MotorRotation.step(-NOMBRE_DE_PAS);
}

void RangerJeux(int JeuxCharge)
{
  int puce=0;
 
  MotorRotation.step(NOMBRE_DE_PAS);
 
  descendre();
 
  digitalWrite(latch, LOW);
  puce = puce + 128;
  shiftOut(data, clock, MSBFIRST, puce);
  digitalWrite(latch, LOW);
 
  Monter();
 
  MotorRotation.step(-NOMBRE_DE_PAS);
 
  Lecteur = pow(2, JeuxCharge-1);
  digitalWrite(latch, LOW);
  puce = puce + lecteur;
  shiftOut(data, clock, MSBFIRST, puce);
  delay(MILISEC_FOR_OPEN_DRIVER);
  puce = puce - lecteur;
  shiftOut(data, clock, MSBFIRST, puce);
  digitalWrite(latch, HIGH);
 
  descendre();
 
  digitalWrite(latch, LOW);
  puce = puce - 128;
  shiftOut(data, clock, MSBFIRST, puce);
  digitalWrite(latch, LOW);
}

void Monter()
{
  do
  {
    digitalRead(CapteurBrasHaut);
    if(CapteurBrasHaut == LOW)
    {
      MotorTranslation.step(-1);
    }
    delay(50);
  }while(CapteurBrasHaut == LOW);
}

He say "Programme_TPE.cpp:31:1: error: expected unqualified-id before '{' token", but i don't see anything wrong at this point of my code.
Anyone?
Using Arduino on Fedora 18 (spherical cow)

I'm a french user, and like many french, as you can see my english is very poor...

PaulS

Quote
but i don't see anything wrong at this point of my code.

I do:
void descendre();

Sinistag

:smiley-eek:
ok that's embarrassing :smiley-roll-sweat:
thanks you for your very fast answer!
but now i have lot of error of undeclared variable:
Code: [Select]
Programme_TPE.cpp: In function 'void descendre()':
Programme_TPE.cpp:38:7: error: 'MotorTranslation' was not declared in this scope
Programme_TPE.cpp: In function 'void loop()':
Programme_TPE.cpp:75:9: error: 'MotorTranslation' was not declared in this scope
Programme_TPE.cpp:93:21: error: too few arguments to function 'void PrendreUnJeux(int)'
Programme_TPE.cpp:12:6: note: declared here
Programme_TPE.cpp: In function 'void RangerJeux(int)':
Programme_TPE.cpp:205:17: error: 'lecteur' was not declared in this scope
Programme_TPE.cpp: In function 'void Monter()':
Programme_TPE.cpp:227:7: error: 'MotorTranslation' was not declared in this scope

have you another magical answer for that please?
(the code is exactly the same excepted for the ';')
Using Arduino on Fedora 18 (spherical cow)

I'm a french user, and like many french, as you can see my english is very poor...

KeithRB

MotorTranslation is commented out.

mistergreen

Is there a guide on how to debug? Some of you gurus should write something.

AWOL

Debugging only starts when the code compiles.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

KeithRB

The best debugging advice ever from Kernigham and Plauger: "The Elements of Programming Style"

"Everyone knows that debugging is twice as hard as writing the program in the first place. So if you are as clever as you can be when you write it, how will you ever debug it?"

Sinistag

i probably need to go to sleep... i'm sorry to ask question who can be very simple for you but the two last error let me perplex.
why compiler say that "Programme_TPE.cpp:205:17: error: 'lecteur' was not declared in this scope"? and why he ask me for more arguments in "void prendreUnJeux"?
Using Arduino on Fedora 18 (spherical cow)

I'm a french user, and like many french, as you can see my english is very poor...

KeithRB

lecteur is not the same as Lecteur.

In case zero you call prendreUnJeux() with no arguments.

GoForSmoke


Is there a guide on how to debug? Some of you gurus should write something.


It's not that simple. Debugging is a multi-aspect skill using knowledge, intuition and persistence. Often lots more persistence than people will believe.

There are many techniques from printing out values to strip-down troubleshooting to walk away and come back fresh but when to do what takes practice to have even a good idea what to try.

Start with persistence and learn from there when to stop beating your head on a wall and look around it, but without persistence most debugging doesn't get far.

Another basic is to learn that often what looks like the problem isn't _the_ problem and it's easy to write bugs into code when trying to rush a job.

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Grumpy_Mike

Quote
why compiler say that "Programme_TPE.cpp:205:17: error: 'lecteur' was not declared in this scope"?

Because it wasn't
If you think it was then it is you that is wrong not the compiler.
The compiler is very stupid, it is easly confused, but it is always right. It is your job to find out why YOU have confused the compiler.

Sinistag

Ok this prove that the error is always from programmer witch don't have to report it on the IDE.
Thank you all, you are very powerful for being able to find that error in a very fast time.
what a long way for me...
Using Arduino on Fedora 18 (spherical cow)

I'm a french user, and like many french, as you can see my english is very poor...

KeithRB

Actually the best debugging tool is knowing the language well enough to execute it yourself, step by step.

AWOL

When you get an error like this
Quote
"Programme_TPE.cpp:205:17: error: 'lecteur' was not declared in this scope"
, the simplest remedy is to do a case-sensitive search in your code for "lecteur".
There should be at least two occurrences, one of which should be a form of declaration.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

retrolefty

A lesson I learned early on when getting started with arduino is that the compiler is great at detecting errors but pretty much sucks at explaining what exactly caused the errors. Once you come to accept that and use the error messages as just vague hints it's not all that bad.

Lefty

Go Up