Hi all, I have a problem joining 2 codes together. Seems like no matter what I do I can't seem to get it to work. This still needs to be added to the code;
void printTemp(void) {
double fTemp;
double temp = Thermister(analogread(0);
lcd.clear();
lcd.setCursor(0,0);
lcd.setCursor(0,1);
ftemp = (temp * 1. + 32.0;
lcd.print(fTemp);
lcd.print( "F" );
}
void loop(void) {
printTemp();
delay(1000);
}
void printTemp(void) {
double fTemp;
double temp = Thermister(analogread(0);
lcd.clear();
lcd.setCursor(0,0);
lcd.setCursor(0,1);
ftemp = (temp * 1. + 32.0;
lcd.print(fTemp);
lcd.print( "F" );
}
void loop(void) {
printTemp();
delay(1000);
}
Code:
/*
originally written by Christian, cptbjorn@gmail.com
*/
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68 //set rtc
#include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins
#include <math.h>
LiquidCrystal lcd(12, 13, 4, 5, 6, 7); // typically 8, 9, 4, 5, 6, 7
// have to change to free up more pwm pins
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();
}
double Thermister(int RawADC) {
double Temp;
// See http://en.wikipedia.org/wiki/Thermistor for explanation of formula
Temp = log(((10240000/RawADC) - 10000));
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
Temp = Temp - 273.15; // Convert Kelvin to Celcius
return Temp;
}
// 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 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.begin(16, 2);
lcd.clear();
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 setup() {
// pinMode(ledPin1, OUTPUT); // set the digital pin as output:
// pinMode(ledPin2, OUTPUT); // set the digital pin as output:
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 = 56;
minute = 57;
hour = 23;
dayOfWeek = 6; // Sunday is 0
dayOfMonth = 26;
month = 2;
year = 11;
//setDateDs1307(second, minute, hour, dayOfWeek, dayOfMonth, month, year);
lcd.begin(16, 2); // set up the LCD's number of rows and columns:
}
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
} // END LOOP