Go Down

Topic: [SOLVED]Only F constant couldn't be known in every procedure scope (Read 805 times) previous topic - next topic

Mar 24, 2012, 07:33 am Last Edit: May 19, 2012, 09:15 pm by MrThinker Reason: 1
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: [Select]

#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: [Select]

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?

Nick Gammon

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.
Please post technical questions on the forum, not by personal message. Thanks!

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

Nick Gammon

For example, if you change F to FOO it compiles OK.
Please post technical questions on the forum, not by personal message. Thanks!

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

Coding Badly


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".

Nick Gammon

Please post technical questions on the forum, not by personal message. Thanks!

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

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.

Coding Badly

@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.

Go Up