I'm using this code to display Time and date on a LCD. Can I do the same without having to use Void Loop(). I'm using a pcf8563 chip with battery backup. any attempt I've made to remove the code from "Loop", just freezes the clock. The clock sketch is below.
How I want it to work, is for the time and date to be displayed until I enter a "Menu". The lcd will then show the "Menu" until I exit back to clock.
I have included the begining of the menu BELOW this sketch.
/* Demonstration of Rtc_Pcf8563 Clock on LCD.
*
* I used a RBBB with Arduino IDE, the pins are mapped a
* bit differently. Change for your hw.
* SCK - A5, SDA - A4, INT - D3/INT1
*
* This sketch connects a lcd to display the clock output.
*
* setup: see Pcf8563 data sheet.
* 1x 10Kohm pullup on Pin3 INT
* No pullups on Pin5 or Pin6 (I2C internals used)
* 1x 0.1pf on power
* 1x 32khz chrystal
* 1x h44780 LCD
*
* Joe Robertson, jmr
* orbitalair@bellsouth.net
*/
#include <Wire.h>
#include <Rtc_Pcf8563.h>
/* add the lcd support */
#include <LiquidCrystal.h>
//init the real time clock
Rtc_Pcf8563 rtc;
/* initialize the library objects */
/* LiquidCrystal lcd(rs, en, d4, d5, d6, d7); */
LiquidCrystal lcd(7,8,9,10,11,12);
void setup()
{
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
//clear out all the registers
rtc.initClock();
//set a time to start with.
//day, weekday, month, century, year
rtc.setDate(14, 4, 1, 20, 13);
//hr, min, sec
rtc.setTime(23, 23, 40);
}
void loop()
{
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 0);
//lcd.print(rtc.formatTime(RTCC_TIME_HM));
lcd.print(rtc.formatTime());
lcd.setCursor(0, 1);
//lcd.print(rtc.formatDate(RTCC_DATE_ASIA));
lcd.print(rtc.formatDate());
delay(1000);
}
and part of my menu
void menuChanged(MenuChangeEvent changed){
MenuItem newMenuItem=changed.to; //get the destination menu
lcd.setCursor(0,0); //set the start position for lcd printing
if(newMenuItem.getName()==menu.getRoot())
{
//lcd.clear();
lcd.print("Main Menu");
}
//MENU SET CLOCK
else if(newMenuItem.getName()=="menuSetClock"){
lcd.clear();
lcd.print("Set Clock");
}
I have tried putting the Clock "loop" code into a function and then calling the function from
if(newMenuItem.getName()==menu.getRoot())
clock();
But all I get is the clock overlaying other menu items because I had to put clock(); in the main Loop otherwise the clock wont update. Do I need an interupt?
My full Sketch is a little long to upload but I can email it .ino