OK here is my complete code:
// AQUATROLLER //
//***************************Arduino Initialisation*********************************************************************************************************************************
#include <LiquidCrystal.h>
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68
#define led_white_pin 10 // Output to white leds on pwm pin 10
#define alarmpin 13 // Output to alarm circuit on digital pin 13
#define led_actinic_pin 9 // Output to actinic leds on pwm pin 9
#define fuge_light_pin 12 // Output to fuge light on digital pin 12
LiquidCrystal lcd(6, 8, 7, 2, 3, 4, 5);
int water_temp_sensor = 3; // Water Temp Sensor connects to input pin 3
int water_temp_c = 0,water_temp_f = 0; // Water temperature variables
int samples[8]; // Water temperature variables to make a better precision
int maxi = -100,mini = 100; // Water integers to start max/min water temperature
int i;
int ph_sensor = 4; // Ph sensor connects to input pin 4
int salt_sensor = 1; // Salinity sensor connects to input pin 1
int HS_value = 0; // Lights Heat Sink Variable
int HS_temp_sensor = 2; // Lights heat Sink Temp sensor on input pin 2
int HS_fanpin = 11; // Output to Heat Sink Fans on pwm pin 11
int HS_temp_c = 0,HS_temp_f = 0; // Lights Heat Sink temperature variables
int HS_samples[8]; // Lights Heat Sink temperature variables to make a better precision
int HSmaxi = -100,HSmini = 100; // Lights Heat Sink integers to start max/min water temperature
int I;
unsigned long last_temperature_check_time = 0; // Time Delay Routine Setup
unsigned long last_lcd_turn_on_time = 0; //
//*************************RTC Intialisation****************************************************************************************************************************************
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
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());
}
void setup()
{
//*******************************Setup Routine of RTC****************************************************************************************************************************
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
Wire.begin(); // Starts 2 wire commuication with RTC module
Serial.begin(9600); // Starts Serial communication with PC
pinMode (HS_fanpin, OUTPUT); // Sets digital pin 6 as an output pin
pinMode (led_white_pin, OUTPUT); // Sets digital pin 5 as an output pin
pinMode (alarmpin, OUTPUT); // Sets digital pin 4 as an output pin
pinMode (led_white_pin, OUTPUT); // Sets digital pin 5 as an output pin
pinMode (led_actinic_pin, OUTPUT); // Sets digital pin 3 as an output pin
pinMode (fuge_light_pin, OUTPUT); // Sets digital pin 2 as an output pin
//*****************************************************************************************
//***************************SET TIME & DATE HERE******************************************
// **********Change these values to what you want to set your clock**************************************************************************************************************
// Remove (//) from front of..... setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
// Then set the time and date and upload to Arduino,
// Then place them back and save program
second = 40;
minute = 23;
hour = 16;
dayOfWeek = 3;
dayOfMonth =11;
month = 3;
year = 9;
// setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
//*******************************************************************************************************************************************************************************
//*******************************************************************************************************************************************************************************
}
void loop()
{
//*****************************Water Temp Time Delay Routine*********************************************************************************************************************
unsigned long time = millis();
if (time - last_temperature_check_time > 5000) // Has it been 5 seconds?
{
last_temperature_check_time = time;
//************************Main Temp Read and Display Routine*******************************************************************************************************************
lcd.clear(); // Clears LCD screen
lcd.print("..AQUATROLLER.."); // Displays AQAUTOLLER on top line
lcd.setCursor(9,5); // Positions cursor for TEMP: label
void alternate_display(void)
{
static int long time = 0;
static byte odd_even = 0;
if (millis() - time > 1000)
{
// code in this block will be executed if a second has elapsed
odd_even = !odd_even;
if (odd_even) // Even
{
// code in this block will execute if Even
lcd.print("WATER:"); // Displays WATER TEMP:
lcd.setCursor(23,5); // Positions cursor for degrees label
lcd.print((char)223); // Displays degrees symbol
lcd.setCursor(24,5); // Positions cursor of F label
lcd.print("F"); // Displays F label
lcd.setCursor(16,1); // Positions cursor for HOOD: label
lcd.print("HOOD:"); // Displays HOOD: label
lcd.setCursor(30,1); // Positions cursor for degrees label
lcd.print((char)223); // Displays degrees symbol
lcd.setCursor(31,1); // Positions cursor for F label
lcd.print("F"); // Displays F label
lcd.setCursor(20,5); // Positions cursor to display WATER TEMP
lcd.print(water_temp_f,DEC); // Sends farenheit water temp to screen
lcd.setCursor(27,1); // Positions cursor to display HOOD TEMP
lcd.print(HS_temp_f,DEC); // Sends farenheit Hood temp to screen
} // end of Even Block
else // Odd
{
lcd.print("SG:"); // Displays Specific Gravity:
lcd.setCursor(20,5);
lcd.print("1.022");
lcd.setCursor(16,1);
lcd.print("PH:");
lcd.setCursor(29,1);
lcd.print("7.8");
} // end of Odd block
} // end if millis check
}