Pages: [1]   Go Down
Author Topic: [SOLVED]Only F constant couldn't be known in every procedure scope  (Read 693 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I followed instruction how to drive 7 segment with adruino from this link: http://makeprojects.com/Project/Drive-a-7-Segment-LED-with-an-Arduino/645/1


Until on Programming Step, a bunch of error happened while I compiled the code. the original code is here: http://bit.ly/ia3lv7. But it showed some error, So, I tried to correct the code. here is my code.

Code:
#define A 8
#define B 9
#define C 2
#define D 3
#define E 4
#define F 5
#define G 6

void clr()
{
  /*Clears the LED*/
  digitalWrite(A, HIGH);
  digitalWrite(B, HIGH);
  digitalWrite(C, HIGH);
  digitalWrite(D, HIGH);
  digitalWrite(E, HIGH);
  digitalWrite(F, HIGH);
  digitalWrite(G, HIGH);
}

void char_A()
{
  digitalWrite(D, HIGH);
  digitalWrite(E, LOW);
 //digitalWrite(F, LOW);
  digitalWrite(G, LOW);
  digitalWrite(A, LOW);
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);
}

void char_B()
{
  //Displays B
  digitalWrite(D, LOW);
  digitalWrite(E, LOW);
  digitalWrite(F, LOW);
  digitalWrite(G, LOW);
  digitalWrite(A, HIGH);
  digitalWrite(B, HIGH);
  digitalWrite(C, LOW);
}

void char_C()
{
  //Displays C
  digitalWrite(D, LOW);
  digitalWrite(E, LOW);
  digitalWrite(F, LOW);
  digitalWrite(G, HIGH);
  digitalWrite(A, LOW);
  digitalWrite(B, HIGH);
  digitalWrite(C, HIGH);
}

void char_D()
{
  //Displays D
  digitalWrite(D, LOW);
  digitalWrite(E, LOW);
  digitalWrite(F, HIGH);
  digitalWrite(G, LOW);
  digitalWrite(A, HIGH);
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);
}

void char_E()
{
  //Displays E
  digitalWrite(D, LOW);
  digitalWrite(E, LOW);
  digitalWrite(F, LOW);
  digitalWrite(G, LOW);
  digitalWrite(A, LOW);
  digitalWrite(B, HIGH);
  digitalWrite(C, HIGH);
}

void char_F()
{
  //Displays F
  digitalWrite(D, HIGH);
  digitalWrite(E, LOW);
  digitalWrite(F, LOW);
  digitalWrite(G, LOW);
  digitalWrite(A, LOW);
  digitalWrite(B, HIGH);
  digitalWrite(C, HIGH);
}

void one()
{
  //Displays 1
  digitalWrite(D, HIGH);
  digitalWrite(E, LOW);
  digitalWrite(F, LOW);
  digitalWrite(G, HIGH);
  digitalWrite(A, HIGH);
  digitalWrite(B, HIGH);
  digitalWrite(C, HIGH);
}

void two()
{
  //Displays 2
  digitalWrite(D, LOW);
  digitalWrite(E, LOW);
  digitalWrite(F, HIGH);
  digitalWrite(G, LOW);
  digitalWrite(A, LOW);
  digitalWrite(B, LOW);
  digitalWrite(C, HIGH);
}

void three()
{
  //Displays 3
  digitalWrite(D, LOW);
  digitalWrite(E, HIGH);
  digitalWrite(F, HIGH);
  digitalWrite(G, LOW);
  digitalWrite(A, LOW);
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);
}

void four()
{
  //Displays 4
  digitalWrite(D, HIGH);
  digitalWrite(E, HIGH);
  digitalWrite(F, LOW);
  digitalWrite(G, LOW);
  digitalWrite(A, HIGH);
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);
}

void five()
{
  //Displays 5
  digitalWrite(D, LOW);
  digitalWrite(E, HIGH);
  digitalWrite(F, LOW);
  digitalWrite(G, LOW);
  digitalWrite(A, LOW);
  digitalWrite(B, HIGH);
  digitalWrite(C, LOW);
}

void six()
{
  //Displays 6
  digitalWrite(D, LOW);
  digitalWrite(E, LOW);
  digitalWrite(F, LOW);
  digitalWrite(G, LOW);
  digitalWrite(A, LOW);
  digitalWrite(B, HIGH);
  digitalWrite(C, LOW);
}

void seven()
{
  //Displays 7
  digitalWrite(D, HIGH);
  digitalWrite(E, HIGH);
  digitalWrite(F, HIGH);
  digitalWrite(G, HIGH);
  digitalWrite(A, LOW);
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);
}

void eight()
{
  //Displays 8
  digitalWrite(D, LOW);
  digitalWrite(E, LOW);
  digitalWrite(F, LOW);
  digitalWrite(G, LOW);
  digitalWrite(A, LOW);
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);
}

void nine()
{
  //Displays 9
  digitalWrite(D, LOW);
  digitalWrite(E, HIGH);
  digitalWrite(F, LOW);
  digitalWrite(G, LOW);
  digitalWrite(A, LOW);
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);
}

void zero()
{
  //Displays 0
  digitalWrite(D, LOW);
  digitalWrite(E, LOW);
  digitalWrite(F, LOW);
  digitalWrite(G, HIGH);
  digitalWrite(A, LOW);
  digitalWrite(B, LOW);
  digitalWrite(C, LOW);
}

void LoopDisplay()
{
  //Loop through all Chars and Numbers
  char_A();
  delay(1000);
  char_B();
  delay(1000);
  char_C();
  delay(1000);
  char_D();
  delay(1000);
  char_E();
  delay(1000);
  char_F();
  delay(1000);
  one();
  delay(1000);
  two();
  delay(1000);
  three();
  delay(1000);
  four();
  delay(1000);
  five();
  delay(1000);
  six();
  delay(1000);
  seven();
  delay(1000);
  eight();
  delay(1000);
  nine();
  delay(1000);
  zero();
  delay(1000);
}

void setup()
{
  //Setup our pins
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT);
  pinMode(E, OUTPUT);
  pinMode(F, OUTPUT);
  pinMode(G, OUTPUT);
  Serial.begin(9600);  //Begin serial communcation

}

void loop()
{
  Serial.println("Starting\n");
  LoopDisplay();
}

And strange error message always appear. here it is.

Code:
seven_segment.cpp: In function 'void clr()':
seven_segment:17: error: 'F' was not declared in this scope
seven_segment.cpp: In function 'void char_B()':
seven_segment:38: error: 'F' was not declared in this scope
seven_segment.cpp: In function 'void char_C()':
seven_segment:50: error: 'F' was not declared in this scope
seven_segment.cpp: In function 'void char_D()':
seven_segment:62: error: 'F' was not declared in this scope
seven_segment.cpp: In function 'void char_E()':
seven_segment:74: error: 'F' was not declared in this scope
seven_segment.cpp: In function 'void char_F()':
seven_segment:86: error: 'F' was not declared in this scope
seven_segment.cpp: In function 'void one()':
seven_segment:98: error: 'F' was not declared in this scope
seven_segment.cpp: In function 'void two()':
seven_segment:110: error: 'F' was not declared in this scope
seven_segment.cpp: In function 'void three()':
seven_segment:122: error: 'F' was not declared in this scope
seven_segment.cpp: In function 'void four()':
seven_segment:134: error: 'F' was not declared in this scope
seven_segment.cpp: In function 'void five()':
seven_segment:146: error: 'F' was not declared in this scope
seven_segment.cpp: In function 'void six()':
seven_segment:158: error: 'F' was not declared in this scope
seven_segment.cpp: In function 'void seven()':
seven_segment:170: error: 'F' was not declared in this scope
seven_segment.cpp: In function 'void eight()':
seven_segment:182: error: 'F' was not declared in this scope
seven_segment.cpp: In function 'void nine()':
seven_segment:194: error: 'F' was not declared in this scope
seven_segment.cpp: In function 'void zero()':
seven_segment:206: error: 'F' was not declared in this scope
seven_segment.cpp: In function 'void setup()':
seven_segment:258: error: 'F' was not declared in this scope

See, "F" was not declared in every scope????

Then, I gave comment mark (using "//") on each line which contains "F" constant. Then I compiled and upload it successfully. I assume all pin works properly except pin 5 (which I set comment each "F" code related).

Why F constant couldn't be known in every procedure scope?
« Last Edit: May 19, 2012, 02:15:09 pm by MrThinker » Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19356
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I using power from my laptop  ...

That's not the problem.

Under version 1.0 of the IDE the word "F" is used to indicate a string is in Flash memory. Better choose another one.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19356
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

For example, if you change F to FOO it compiles OK.
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13085
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


F is a macro defined by the Arduino environment.  Some details are available here...

http://arduino.cc/forum/index.php?topic=91314.0.html

I suggest using something other than "F" to avoid the conflict; maybe "sF" for "segment F".
Logged

Global Moderator
Melbourne, Australia
Offline Offline
Brattain Member
*****
Karma: 511
Posts: 19356
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@CB: ninja by 12 seconds!
Logged

http://www.gammon.com.au/electronics

Please post technical questions on the forum - not to me by personal message. Thanks a lot.

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, it seems "F" has been one of reserved word in adruino programming environment and I should use another name. suddenly clear the problem. thanks.
Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13085
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@CB: ninja by 12 seconds!

Argh!  Bested by an Aussie!  I have a reasonable excuse.  I was letting my Australian Terrier outside.  She wanted to yell at the neighborhood skunk.
Logged

Pages: [1]   Go Up
Jump to: