Go Down

Topic: add hours and days on timecounter (Read 917 times) previous topic - next topic


I am running this code copied from here http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1227406778/all
Thiw code just count time since reset
I need to insert button for changing hours  on counter.
Fow example if time is 3 hours and 32 min ,by pressing the button 2 times the new time will be 5 hours and 32 min.
I was tring to find command of change  DateTime.Hour and DateTime.Day   (etc DateTime.Hour++) but nothing happend
Anyone knows those commands (-- and ++) please help

Code: [Select]
#include <DateTime.h>
#include <LiquidCrystal.h>

int resetPin = 3; // pin 3 resets the time

//create object to control an LCD GMD1602K.
LiquidCrystal lcd(12, 11, 2, 7, 8, 9, 10);

void setup(){
digitalWrite(resetPin,HIGH);  // this line enables pull-up
pinMode(13,OUTPUT);          // we flash the LED each second
pinMode(resetPin, INPUT);    // a button on this pin resets the time
DateTime.sync( 0 );             // set time to zero

void loop(){
if(digitalRead(resetPin) == LOW)
     DateTime.sync( 0 );      // reset time to zero if button pressed

/* --------- Prints time in hours, minutes and seconds ----------- */
DateTime.available(); // needed to refresh the clock time
time_t timeNow = DateTime.now();
lcd.print(timeNow/60);        // total elapsed minutes
lcd.print(timeNow/3600);    //  total elapsed seconds

lcd.print(DateTime.Hour,DEC);      // prints total hours (up to 24)
lcd.print(DateTime.Minute,DEC);   // and minutes since reset
lcd.print(DateTime.Second,DEC);  // and seconds since reset
lcd.print(" ");                               // clears second digit every minute

digitalWrite(13, LOW);                  //light the LED every second
delay (1000);
digitalWrite(13, HIGH);                 //


It isn't clear what you are trying to. On every pass through loop, you call the DateTime.now() function, which obtains the current time, again. Incrementing the Hour and Minute variables, and then resetting them nanoseconds later does not seem useful.


Apr 06, 2011, 01:14 pm Last Edit: Apr 06, 2011, 01:16 pm by dalai Reason: 1
No I dont want to reset them
pin for increase Hour and Minute variables will be in other pins  (not in pin 3 (reset pin) )

I want to add a code like this
void loop(){
if(digitalRead(increaseHourPin) == LOW)
    hour++;      // increase hour by one (this is the command i dont know)

if(digitalRead(increaseMinPin) == LOW)
  minute ++ ;      // increase min by one (this is the command i dont know)


Code: [Select]
     hour++;      // increase hour by one (this is the command i dont know)
That command is correct, assuming you do something like this, first:

Code: [Select]
int hour = DateTime.Hour;

You can not, the way the code you posted initially is structured, increment DateTime.Hour, because DateTime.Hour is set back to the current time on every pass through loop.


Go Up