ok so what im trying to do is display time and Temps from a DS1307 and LM35 on a 4x20 serial LCD. i can do them individually with a separate programs for each, but i would like to put them into one program and use a momentary switch to change what the LCD is displaying.
like when the Arduino starts it displays the time. then i would have two momentary switches below the LCD, one when pressed would show temps on the lcd, the other when pressed would show time.
the arduino code
////////TEMPS////////
#include <SoftwareSerial.h>
#define txPin 2
//LM35 Pin Variables
int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures
SoftwareSerial LCD = SoftwareSerial(0, txPin);
// since the LCD does not send data back to the Arduino, we should only define the txPin
const int LCDdelay=10; // conservative, 2 actually works
// wbp: goto with row & column
void goTo(int row, int col) {
LCD.print(0xFE, BYTE); //command flag
LCD.print((col + row*64 + 128), BYTE); //position
delay(LCDdelay);
}
void clearLCD(){
LCD.print(0xFE, BYTE); //command flag
LCD.print(0x01, BYTE); //clear command.
delay(LCDdelay);
}
void backlightOn() { //turns on the backlight
LCD.print(0x7C, BYTE); //command flag for backlight stuff
LCD.print(157, BYTE); //light level.
delay(LCDdelay);
}
void backlightOff(){ //turns off the backlight
LCD.print(0x7C, BYTE); //command flag for backlight stuff
LCD.print(128, BYTE); //light level for off.
delay(LCDdelay);
}
void serCommand(){ //a general function to call the command flag for issuing all other commands
LCD.print(0xFE, BYTE);
}
void setup()
{
pinMode(txPin, OUTPUT);
LCD.begin(9600);
clearLCD();
}
void loop() // run over and over again
{
//getting the voltage reading from the temperature sensor
int reading = analogRead(sensorPin);
// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = reading * 5.0;
voltage /= 1024.0;
// print out the voltage
//Serial.print(voltage); Serial.println(" volts");
// now print out the temperature
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((volatge - 500mV) times 100)
//Serial.print(temperatureC); Serial.println(" degress C");
// now convert to Fahrenheight
int temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
goTo(0,0);
LCD.print(temperatureF);
LCD.print(" degrees F");
delay(900);
clearLCD();
delay(100); //waiting a second
}
//////TIME//////
/*
* TimeRTC.pde
* example code illustrating Time library with Real Time Clock.
*
*/
#include <Time.h>
#include <Wire.h>
#include <DS1307RTC.h>// a basic DS1307 library that returns time as a time_t
#include <SoftwareSerial.h>
#define txPin 2
SoftwareSerial LCD = SoftwareSerial(0, txPin);
// since the LCD does not send data back to the Arduino, we should only define the txPin
const int LCDdelay=10; // conservative, 2 actually works
// wbp: goto with row & column
void goTo(int row, int col) {
LCD.print(0xFE, BYTE); //command flag
LCD.print((col + row*64 + 128), BYTE); //position
delay(LCDdelay);
}
void clearLCD(){
LCD.print(0xFE, BYTE); //command flag
LCD.print(0x01, BYTE); //clear command.
delay(LCDdelay);
}
void backlightOn() { //turns on the backlight
LCD.print(0x7C, BYTE); //command flag for backlight stuff
LCD.print(157, BYTE); //light level.
delay(LCDdelay);
}
void backlightOff(){ //turns off the backlight
LCD.print(0x7C, BYTE); //command flag for backlight stuff
LCD.print(128, BYTE); //light level for off.
delay(LCDdelay);
}
void serCommand(){ //a general function to call the command flag for issuing all other commands
LCD.print(0xFE, BYTE);
}
void setup() {
pinMode(txPin, OUTPUT);
LCD.begin(9600);
clearLCD();
setSyncProvider(RTC.get); // the function to get the time from the RTC
if(timeStatus()!= timeSet)
{
goTo(0,0);
LCD.print("Unable to sync with the RTC");
}
else
{
goTo(0,0);
LCD.print("RTC has set the system time");
delay(250);
clearLCD();
}
timeStatus_t timeStatus();
}
void loop()
{
digitalClockDisplay();
delay(1000);
}
void digitalClockDisplay(){
// digital clock display of the time
goTo(0,0);
LCD.print(hour());
printDigits(minute());
printDigits(second());
LCD.print(" ");
LCD.print(day());
LCD.print(" ");
LCD.print(month());
LCD.print(" ");
LCD.print(year());
LCD.println();
}
void printDigits(int digits){
// utility function for digital clock display: prints preceding colon and leading 0
LCD.print(":");
if(digits < 10)
LCD.print('0');
LCD.print(digits);
}
thanks!