I want to use two buttons to display two different things on a 16 x 1 LCD. One button would display the temperature and the other button would allow me to display the clock. I do have both programs working separately and I’m trying to figure how I can use buttons to control my options.
Code for temperature:
#include <LiquidCrystal440.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 9
OneWire oneWire(ONE_WIRE_BUS);
int heater;
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer = { 0x10, 0x37, 0xBC, 0x1E, 0x02, 0x08, 0x00, 0xE9 };
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int LED = 10;
void setup()
{
pinMode(LED, OUTPUT);
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(insideThermometer, 10);
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
lcd.begin(8,2);
lcd.print("Temp: ");
lcd.print(DallasTemperature::toFahrenheit(tempC));
lcd.print((char)223);
lcd.print((char)70);
if (DallasTemperature::toFahrenheit(tempC) < 78.00)
heater = 1;
else
heater = 0;
}
void loop()
{
sensors.requestTemperatures();
printTemperature(insideThermometer);
if (heater ==1){
digitalWrite(LED, HIGH);
} else {
digitalWrite(LED, LOW);
}
lcd.setCursor(0, 0);
}
code for clock:
#include <LiquidCrystal440.h>
#include <DateTime.h>
#include <DateTimeStrings.h>
#define dt_SHORT_DAY_STRINGS
#define dt_SHORT_MONTH_STRINGS
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup(){
DateTime.sync(DateTime.makeTime(0, 4, 5, 16, 10, 2010)); // sec, min, hour, date, month, year // Replace this with the most current time
}
void loop()
{
if(DateTime.available()) {
unsigned long prevtime = DateTime.now();
while( prevtime == DateTime.now() ) // wait for the second to rollover
;
DateTime.available(); //refresh the Date and time properties
digitalClockDisplay( ); // update digital clock
}
}
void printDigits(byte digits){
// utility function for digital clock display: prints preceding colon and leading 0
lcd.print(":");
if(digits < 10)
lcd.print('0');
lcd.print(digits,DEC);
}
void digitalClockDisplay(){
lcd.clear();
lcd.begin(8,2);
lcd.setCursor(0,0);
lcd.print("Time:");
//lcd.print(" ");
if(DateTime.Hour <10)
lcd.setCursor(7,0);
// digital clock display of current time
lcd.print(DateTime.Hour,DEC);
printDigits(DateTime.Minute);
printDigits(DateTime.Second);
}
Any suggestion on how I should approach this besides getting a 16 x 2 LCD?