Pages: [1]   Go Down
Author Topic: Error Message  (Read 355 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, I am getting my arduino on Christmas and I want to have some kind of a project ready before then, but when i click verify it gives me a error message that I don't understand and would like help with.

The error message is:  error: expected ',' or '...' before numeric constant

I have started o learn arduino code on Thursday and because I have learned some of Turing and I am a good logical thinker I have created this.
This will control bunch of LED's to create a number and change it to the next one.
If the button is pressed then right now one LED blinks and when I will figure out the error then I will make itso another button changes it on command.
Code:
#define t 2   //Top LED's
#define tl 3  //Top Left LED's
#define tr 4  //Top Right LED's
#define m 5   //Middle LED's
#define bl 6  //Bottom Left LED's
#define br 7  //Bottom Right LED's
#define b 8   //Bottom LED's
#define d 9   //Dot
#define s 10  //Button
#define de 100  //delay
int n = 0;
int number0(){
  digitalWrite (t, HIGH);
  digitalWrite (tl, HIGH);
  digitalWrite (tr, HIGH);
  digitalWrite (bl, HIGH);
  digitalWrite (br, HIGH);
  digitalWrite (b, HIGH);
  n = 0;
}
int number1(){
  digitalWrite (t, LOW);
  digitalWrite (tr, HIGH);
  digitalWrite (tl, LOW);
  digitalWrite (m, LOW);
  digitalWrite (br, HIGH);
  digitalWrite (bl, LOW);
  digitalWrite (b, LOW);
  n = 1;
}
int number2(){
  digitalWrite (t, HIGH);
  digitalWrite (tr, HIGH);
  digitalWrite (tl, LOW);
  digitalWrite (m, HIGH);
  digitalWrite (br, LOW);
  digitalWrite (bl, HIGH);
  digitalWrite (b, HIGH);
  n = 2;
}
int number3(){
  digitalWrite (t, HIGH);
  digitalWrite (tr, HIGH);
  digitalWrite (tl, LOW);
  digitalWrite (m, HIGH);
  digitalWrite (br, HIGH);
  digitalWrite (bl, LOW);
  digitalWrite (b, HIGH);
  n = 3;
}
int number4(){
  digitalWrite (t, LOW);
  digitalWrite (tr, HIGH);
  digitalWrite (tl, HIGH);
  digitalWrite (m, HIGH);
  digitalWrite (br, HIGH);
  digitalWrite (bl, LOW);
  digitalWrite (b, LOW);
  n = 4;
}
int number5(){
  digitalWrite (t, HIGH);
  digitalWrite (tr, LOW);
  digitalWrite (tl, HIGH);
  digitalWrite (m, HIGH);
  digitalWrite (br, HIGH);
  digitalWrite (bl, LOW);
  digitalWrite (b, HIGH);
  n = 5;
}
int number6(){
  digitalWrite (t, HIGH);
  digitalWrite (tr, LOW);
  digitalWrite (tl, HIGH);
  digitalWrite (m, HIGH);
  digitalWrite (br, HIGH);
  digitalWrite (bl, HIGH);
  digitalWrite (b, HIGH);
  n = 6;
}
int number7(){
  digitalWrite (t, HIGH);
  digitalWrite (tr, HIGH);
  digitalWrite (tl, LOW);
  digitalWrite (m, LOW);
  digitalWrite (br, HIGH);
  digitalWrite (bl, LOW);
  digitalWrite (b, LOW);
  n = 7;
}
int number8(){
  digitalWrite (t, HIGH);
  digitalWrite (tr, HIGH);
  digitalWrite (tl, HIGH);
  digitalWrite (m, HIGH);
  digitalWrite (br, HIGH);
  digitalWrite (bl, HIGH);
  digitalWrite (b, HIGH);
  n = 8;
}
int number9(){
  digitalWrite (t, HIGH);
  digitalWrite (tr, HIGH);
  digitalWrite (tl, HIGH);
  digitalWrite (m, HIGH);
  digitalWrite (br, HIGH);
  digitalWrite (bl, LOW);
  digitalWrite (b, HIGH);
  n = 9;
}
void setup ()
{
  for (int x = t; x <= d; x++) {
    pinMode (x, OUTPUT);
  }
  pinMode (s, INPUT);
  digitalWrite (t, HIGH);
  digitalWrite (tl, HIGH);
  digitalWrite (tr, HIGH);
  digitalWrite (bl, HIGH);
  digitalWrite (br, HIGH);
  digitalWrite (b, HIGH);
  digitalWrite (d, HIGH);
}
void loop ()
{
  while (digitalRead == LOW){
    switch (n){
      case 0:
      number0();
      case 1:
      number1();
      case 2:
      number2();
      case 3:
      number3();
      case 4:
      number4();
      case 5:
      number5();
      case 6:
      number6();
      case 7:
      number7();
      case 8:
      number8();
      case 9:
      number9();
    }
    if (n == 9){
      n = 0;
    }
    else {
    n++;
    }
  }
  digitalWrite (d, LOW);
  delay (100);
  digitalWrite (d, HIGH);
  delay (100);
}
Logged

North Queensland, Australia
Offline Offline
Edison Member
*
Karma: 70
Posts: 2171
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

you need break statements in your switch it seems, each number function lights the other lights for you,

without the break, case 5 executes.

Code:
     
number5();
number6();
number7();
number8();
number9();

you should post the line number of the error

EDIT: n or your some of your defines are defined in the core ( WString.h apparantly ),

change the names to something meaningful and the errors will go.

your number functions need return values
« Last Edit: December 19, 2011, 11:05:13 pm by pYro_65 » Logged


Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The problem is here...

Code:
#define t 2   //Top LED's
#define tl 3  //Top Left LED's
#define tr 4  //Top Right LED's
#define m 5   //Middle LED's
#define bl 6  //Bottom Left LED's
#define br 7  //Bottom Right LED's
#define b 8   //Bottom LED's
#define d 9   //Dot
#define s 10  //Button
#define de 100  //delay

#define is a compiler directive. What it does is replace all occurrences of the first parameter with the second parameter within the code, prior to compilation. So, with your #defines, all occurrences of the letter 't' are replaced with the digit '2', all 'b's with '8's, and so on. The result of this is, for example, the function digitalWrite() becomes 9igi2alWri2e(), and the compiler doesn't have a clue what you mean.

Moral: If you are going to use #define, make sure you consider the results.

You do need breaks in the switch/case bit.

 
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49365
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The result of this is, for example, the function digitalWrite() becomes 9igi2alWri2e(), and the compiler doesn't have a clue what you mean.
No, that does not happen. All occurrences of t as a word, not as a letter, are replaced.

The problem IS with the #define statements, but it is because of a bug in the way that the IDE added code to the sketch. Move the int n=0; statement ABOVE the #defines, and the problem goes away.
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah, ok. Right area, wrong reason. Thanks for the explanation. Still learning myself.
Logged

Pages: [1]   Go Up
Jump to: