Hi all, back again. This is a new problem. I cannot for the life of me figure out why my time will not display on my lcd. If I strip everything else out of the program except the time parts it will display with no problem.Here's the code, any ideas:
#define DS1307_I2C_ADDRESS 0x68 // address used for clock
#include "Wire.h" // library used
#include <LiquidCrystal.h> // library used
#include <RTClib.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 8 //Define the pin of the DS18B20
RTC_DS1307 RTC;
int heater = A0; // heater relay , digital pin 0
int moon = A1; // moon light relay connected to analog pin 1
int heater_on_temp = 78; //Turn on heater at this temp
int heater_off_temp = 80; //turn heater off once below this temp
int backLight = 13;
int ledPin = 7; // Set our LED pin
byte startHour = 12; // Set our start and end times
byte startMinute = 00; // Don't add leading zero to hour or minute - 7, not 07
byte endHour = 12; // Use 24h format for the hour, without leading zero
byte endMinute = 01;
byte validStart = 0; // Declare and set to 0 our start flag
byte poweredOn = 0; // Declare and set to 0 our current power flag
byte validEnd = 0; // Declare and set to 0 our end flag
LiquidCrystal lcd( 12, 11, 10, 5, 4, 3, 2);
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);
}
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : H E A T E R O N |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void HeaterOn()
{
digitalWrite(heater, LOW);
lcd.setCursor(9, 2);
lcd.print("ON ");
}
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : H E A T E R O F F |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void HeaterOff()
{
digitalWrite(heater, HIGH);
lcd.setCursor(9, 2);
lcd.print("OFF");
}
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : M O O N L I G H T O N |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void MoonOn()
{
digitalWrite(moon, LOW);
lcd.setCursor(6,3);
lcd.print("ON ");
}
/*||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| D E F I N E : M O O N L I G H T O F F |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
void MoonOff()
{
digitalWrite(moon, HIGH);
lcd.setCursor(6,3);
lcd.print("OFF");
}
void backlight()
{
digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
}