Go Down

Topic: Not declared in this scope (Read 541 times) previous topic - next topic

rjhudak1

Hi all, I am back again, What I did was to try and put a timer sketch into my rtc sketch and for the life of me I can not figure out why I keep getting the message "not declared in this scope" Here's the sketch
Code: [Select]
/* the checkStartTime, checkEndTime, turnOnLights, and turnOff Lights are my problems, Any help would greatly be appreciated.

originally written by Christian, cptbjorn@gmail.com

*/


#include "Wire.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#define DS1307_I2C_ADDRESS 0x68 //set rtc
#include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins
#define ONE_WIRE_BUS 8 //Define the pin of the DS18B20
#include <RTClib.h>
RTC_DS1307 RTC;

/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  R E L A Y   P A R T  |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  S I M P L E   O N   A N D   O F F   F E A T U R E |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



const int ledPin1 =  A0;          // pin number for relay 1
const int ledPin2 =  A1;          // pin number for relay 2


int ledState1 = LOW;             
int ledState2 = LOW;
long previousMillis1 = 0;       
long previousMillis2 = 0;
long interval1 = 30000;          // interval at which to blink (milliseconds) for RELAY1
long interval2 = 50000; // interval at which to blink (milliseconds) for RELAY2


/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  L E D   D I M M I N G   P A R T  |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  F A D E S   I N   A N D   O U T  |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



int backLight = 13;
int heater_on_temp = 78;   //Turn on heater at this temp
int heater_off_temp = 80;  //turn heater off once below this temp
int heater = A2;
int ledPin = A3;
int startHour = 20;
int startMinute = 24;
int endHour = 20;
int endMinute = 25;
int validStart = 0;
int poweredOn = 0;
int validEnd = 0;

LiquidCrystal lcd( 12, 11, 10, 5, 4, 3, 2);   // typically 8, 9, 4, 5, 6, 7
                                         // have to change to free up more pwm pins
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);


/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  R T C   C L O C K   D S 1 3 0 7  |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



byte decToBcd(byte val)    // Convert normal decimal numbers to binary coded decimal
{
  return ( (val/10*16) + (val%10) );
}


byte bcdToDec(byte val)    // Convert binary coded decimal to normal decimal numbers
{
  return ( (val/16*10) + (val%16) );
}

// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
// Assumes you're passing in valid numbers
void setDateDs1307(byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayOfWeek, // 1-7
byte dayOfMonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.send(0);
  Wire.send(decToBcd(second)); // 0 to bit 7 starts the clock
  Wire.send(decToBcd(minute));
  Wire.send(decToBcd(hour));   // If you want 12 hour am/pm you need to set
  // bit 6 (also need to change readDateDs1307)
  Wire.send(decToBcd(dayOfWeek));
  Wire.send(decToBcd(dayOfMonth));
  Wire.send(decToBcd(month));
  Wire.send(decToBcd(year));
  Wire.endTransmission();
}

// Gets the date and time from the ds1307
void getDateDs1307(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  // Reset the register pointer
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.send(0);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);

  // A few of these need masks because certain bits are control bits
  *second = bcdToDec(Wire.receive() & 0x7f);
  *minute = bcdToDec(Wire.receive());
  *hour = bcdToDec(Wire.receive() & 0x3f); // Need to change this if 12 hour am/pm
  *dayOfWeek = bcdToDec(Wire.receive());
  *dayOfMonth = bcdToDec(Wire.receive());
  *month = bcdToDec(Wire.receive());
  *year = bcdToDec(Wire.receive());
}



/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  D E F I N E  :  O N E S E C O N D |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



void onesecond() //function that runs once per second while program is running
{
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  lcd.setCursor(0, 0);
  if(hour>0)
  {
    if(hour<=12)
    {
      lcd.print(hour, DEC);
    }
    else
    {
      lcd.print(hour-12, DEC);
    }
  }
  else
  {
    lcd.print("12");
  }
  lcd.print(":");
  if (minute < 10) {
    lcd.print("0");
  }
  lcd.print(minute, DEC);
  lcd.print(":");
  if (second < 10) {
    lcd.print("0");
  }
  lcd.print(second, DEC);
  if(hour<12)
  {
    lcd.print("am");
  }
  else
  {
    lcd.print("pm");
  }
  lcd.print(" ");
  delay(1000);
}

void backlight()
{
   digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.

/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  D E F I N E  :  H E A T E R    O N |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void HeaterOn()
{
  digitalWrite(heater, HIGH); 
  lcd.setCursor(9, 2);
  lcd.print("ON ");
  //analogWrite(fan, 255);
   
}
/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  D E F I N E  :  H E A T E R    O F F |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void HeaterOff()
{
  digitalWrite(heater, LOW);
  lcd.setCursor(9, 2);
  lcd.print("OFF");
    //analogWrite(fan, 0);
   
}




/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  S E T U P  |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/


void setup() {
  pinMode(ledPin1, OUTPUT);    // set the digital pin as output:
  pinMode(ledPin2, OUTPUT);    // set the digital pin as output:
  pinMode(backLight, OUTPUT);
  digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
// pinMode(lights, OUTPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  Wire.begin();
  RTC.begin();
 
  //if (! RTC.isrunning()) {
   // Serial.println("RTC is Not running!");
   // RTC.adjust(DateTime(_2DATE13_,_6TIME51_));
  //}
   sensors.begin();
  /*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  S E T U P - D I S P L A Y |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/



  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  Wire.begin();

  // Change these values to what you want to set your clock to.
  // You probably only want to set your clock once and then remove
  // the setDateDs1307 call.
  second = 36;
  minute = 59;
  hour = 9;
  dayOfWeek = 6;  // Sunday is 0
  dayOfMonth = 26;
  month = 2;
  year = 11;
// setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);

 
  lcd.begin(20, 4); // set up the LCD's number of rows and columns:
  lcd.setCursor(0, 1);
  lcd.setCursor(0, 2);
  lcd.print("Heater:"); 
}


/*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||  L O O P |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/




void loop()
{
  onesecond();
 

  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
  getDateDs1307(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month, &year);
  int daybyminute = ((hour * 60) + minute); //converts time of day to a single value in minutes

// DS18B20 display
sensors.requestTemperatures(); // Send the command to get temperatures
    // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
//

  lcd.setCursor(11, 0);
  lcd.print(sensors.getTempFByIndex(0)); 
  lcd.print((char)223);
  if (sensors.getTempFByIndex(0) < heater_on_temp)  HeaterOn(); 
  if (sensors.getTempFByIndex(0) > heater_off_temp)  HeaterOff();
  lcd.setCursor(9, 2);
  delay(1000);
 
DateTime now = RTC.now();
 
  if (now.second() == 0) {
    if (poweredOn == 0) {
    checkStartTime();
  } else {
    checkEndTime();
  }
 
  if (validStart == 1) {
    turnLightsOn();
  }
  if (validEnd == 1) {
    turnLightsOff();
  }
}
delay(1000);
//}

byte checkStartTime() {
   DateTime now = RTC.now();
   
   if (now.hour() ==startHour && now.minute() == startMinute) {
     validStart = 1;
     poweredOn = 1;
   } else {
     validStart = 0;
   }
return validStart;
}
byte checkEndTime() {
DateTime now = RTC.now();

  if (now.hour() == endHour && now.minute() == endMinute) {
   validEnd = 1;
  poweredOn = 0;
  } else {
   validEnd = 0;
  }
return validEnd;
}
void turnLightsOn() {
  digitalWrite(ledPin, HIGH);
}
void turnLightsOff() {
  digitalWrite(ledPin, LOW);


      }   // END LOOP

PaulS

Quote
Here's the sketch

And the error message(s)?

You are using a lot of libraries that not everyone has installed. If I don't have them, and I get some totally different error message(s) than you, solving my problem won't help you. If I do have them, and you don't, knowing that it compiled for me won't help you.

dxw00d

At a quick glance, you are trying to define functions inside loop().

tuxduino


At a quick glance, you are trying to define functions inside loop().


I agree.

Please do yourself and your code readers a favor and hit CTRL-T in the Arduino IDE. Spotting this kind of errors will be much easier, IMHO.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy