Go Down

Topic: [SOLVED] int not declared in the scope (Read 383 times) previous topic - next topic

tigerbomb8

Feb 11, 2012, 02:35 pm Last Edit: Feb 11, 2012, 02:42 pm by tigerbomb8 Reason: 1
hey guys and gals
this is my problem.
for some reason it keeps coming up with "lightval not declared in this scope". i have no idea why. can someone please tell my what i am missing
this is the part giving me problems
Quote

void sunset() {
 do{
   delay(50);
   int lightval = analogRead(1);
 } while (lightval > 60)
 
 for (int brightness = 255; brightness >= 0; brightness--) {
  analogWrite(9, brightness);
  delay(3500);
}
}

and this is the full code
Code: [Select]
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 RTC;

 int amhour = 11;
 int ammin = 0;
 int amsec = 0;
 int pmhour = 21;
 int pmmin = 15;
 int pmsec = 0;
 int brightness;

void setup () {
 Serial.begin(57600);
 Wire.begin();
 RTC.begin();
 
 pinMode(9, OUTPUT);
 
 DateTime now = RTC.now();
 
 int hourval = now.hour();
 int minval = now.minute();
 int secval = now.second();
 
 
 on();
 
 if (hourval >= 12 && hourval <= 20) {
   analogWrite(9, 255);
 }
 
 else analogWrite(9, 0);
 
 if (! RTC.isrunning()) {
 Serial.println("RTC is NOT running!");
 RTC.adjust(DateTime(__DATE__, __TIME__));
 
 }
}

void loop() {
 DateTime now = RTC.now();
 
 int hourval = now.hour();
 int minval = now.minute();
 int secval = now.second();
 
 
 if (secval == amsec && minval == ammin && hourval == amhour) {
  sunrise();
 }
 
 if (secval == pmsec && minval == pmmin && hourval == pmhour) {
  sunset();
 }

 Serial.print(hourval);
 Serial.print(':');
 Serial.print(minval);
 Serial.print(':');
 Serial.print(secval);
 Serial.println();
 
 delay(1000);
 
}

void sunrise() {
 
for (int brightness = 0; brightness <= 255; brightness++) {
  analogWrite(9, brightness);
  delay(3500);
}
}

void sunset() {
 do{
   delay(50);
   int lightval = analogRead(1);
 } while (lightval > 60)
 
 for (int brightness = 255; brightness >= 0; brightness--) {
  analogWrite(9, brightness);
  delay(3500);
}
}

void on() {
 for (int on = 0; on <= 255; on++)
 {
  analogWrite(9, on);
  delay(5);
}

for (int off = 255; off >= 0; off--)
{
  analogWrite(9, off);
  delay(5);
}
}



PaulS

Time to read up on scope.
Code: [Select]
  do{
    delay(50);
    int lightval = analogRead(1);
  } while (lightval > 60)

The scope for lightval ends when the do/while statement ends. If you want to use lightval after that, it must not be local to the do/while loop.

tigerbomb8

ok i got it now..... thanks for your help

Go Up