Pages: [1]   Go Down
Author Topic: [SOLVED] int not declared in the scope  (Read 370 times)
0 Members and 1 Guest are viewing this topic.
Down Under (Australia), SA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 88
Newbie is an understatement
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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);
 }
}

« Last Edit: February 11, 2012, 08:42:14 am by tigerbomb8 » Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 652
Posts: 50863
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Time to read up on scope.
Code:
  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.
Logged

Down Under (Australia), SA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 88
Newbie is an understatement
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: