Pages: [1]   Go Down
Author Topic: "was not declared in this scop" error  (Read 598 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
God Member
*****
Karma: 0
Posts: 529
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What dose this mean?

Getting it when I try and upload this code

Code:
// CountDownTest Joe Pardue 8/15/09

int seconds = 59;
int minutes = 59;     // Inititialise actual values for h,m,s

void setup () {
  // begin the serial communication
  Serial.begin(9600);
}

void loop () {

    seconds = seconds - 1;  // decrement the seconds
    tick = 0;               // reset the tick flag
    if (seconds < 0){       // If a minute has passed
      seconds = 59 ;         // Send seconds up to 59
      minutes = minutes - 1; // decrement the minutes
    }
  
    Serial.print(minutes,DEC);
    Serial.print(":");
    Serial.println(seconds,DEC);
 
    delay(1000); // wait a second
}
 
Logged

0
Offline Offline
God Member
*****
Karma: 0
Posts: 572
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You didn't post the whole error - you should have said " In function 'void loop()':
error: 'tick' was not declared in this scope"

You have a line which says

Code:
tick = 0;               // reset the tick flag

You never initialised this variable - you did for the variables "seconds" and "minutes".

Either initialise the variable (int tick =0;), or seeing as how you don't actually use the variable tick, just delete the above line from your code.
Logged

UK
Offline Offline
God Member
*****
Karma: 0
Posts: 529
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your absolutely right, I understand the error now, missed the "In function 'void loop()':"  ;D
Logged

Finland
Offline Offline
Sr. Member
****
Karma: 1
Posts: 270
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Btw, your code won't implement an accurate clock. All the code, not only delay(), will take some time to execute, especially Serial.print[ln]() calls. So the constant delay of 1000 ms won't work. You can use millis() to calculate more accurate delay-time.
Logged

UK
Offline Offline
God Member
*****
Karma: 0
Posts: 529
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you very much for that, Im trying to change the code to print onto 4 7-segment LEDs (but not having much luck)

But I guess I will still need to use millis() when i finally work it out, so thank you!
Logged

Pages: [1]   Go Up
Jump to: