LCD DISPLAY CODING

hai

i am new here. so i am doing a project for my final year project, that counts days until certain date. i have managed to display the current day, date and time on the lcd. the problem is i dont have any idea how to display the countdown for the amount of days left.

i have found a page that does the exact same project as mine, but the difference is that it doesnt use any coding. here is the page Siliconfish: Arduino LCD Countdown Clock

the screen capture and my coding as enclosed. i really hope that you can help, thank you so much !! :-*

barunya_ds_1307.ino (1.47 KB)

I have not read the code. I wonder why this countdown display part is difficult given that you have successfully done all the other part.

Please explain what the difficulty is.

Calculate days remaining
Position cursor
Output the value

Weedpharma

Just for the sheer hell of it, here's a stab (I haven't run it so you'll probably have some debugging to do)

typedef struct plainDT
  {int year;
   int month;
   int day;
   int hour;
   int minute;
   int second;
  };

plainDT targetDate={2017, 12, 25, 0, 0, 0}; //Christmas day 2017  
plainDT diff;
char diffString[21];

#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
RTC_DS1307 RTC;
 
void setup () {
    Serial.begin(9600);
    Wire.begin();
    RTC.begin();
     lcd.begin(20, 4);
    
   pinMode(8,OUTPUT);
 
  if (! RTC.isrunning()) {
   Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
   RTC.adjust(DateTime(__DATE__, __TIME__));
  }
}
 
void loop () {
    DateTime now = RTC.now();
    lcd.setCursor(0, 0);
    lcd.print("Digital Clock");
    lcd.setCursor(0, 1);
    lcd.print(now.day(), DEC);
    lcd.print('/');
    lcd.print(now.month(), DEC);
    lcd.print('/');
    lcd.print(now.year(), DEC);
    lcd.print(' ');
    lcd.setCursor(0, 2);
     if (now.hour()<10)
    lcd.print('0');
    lcd.print(now.hour(), DEC);
    lcd.print(':');
     if (now.minute()<10)
    lcd.print('0');
    lcd.print(now.minute(), DEC);
    lcd.print(':');
    if (now.second()<10)
    lcd.print('0');
    lcd.print(now.second(), DEC);
    lcd.setCursor(0, 3);
   int dayofweek = now.dayOfWeek();
   switch(dayofweek){
     case 1:
     lcd.print("Monday");
     break;
     case 2:
     lcd.print("Tuesday");
     break;
     case 3:
     lcd.print("Wednesday");
     break;
     case 4:
     lcd.print("Thursday");
     break;
     case 5:
     lcd.print("Friday");
     break;
     case 6:
     lcd.print("Saturday");
     break;
     case 0:
     lcd.print("Sunday");
     break;
  }
calculate();
lcd.setCursor(0,0);
lcd.print(diffString);
delay(1000); 
}
    
  
void calculate()
{
DateTime now=RTC.now();
plainDT TARGET=targetDate;
plainDT NOW={now.year(),now.month(),now.day(),now.hour(),now.minute(),now.second()};

//makes maths easier if months are zero based
TARGET.month--; 
NOW.month --;

int maxDays[]={31,28,31,30,31,30,31,31,30,31,30,31};
int dayCount=maxDays[NOW.month];
if ( (NOW.month==1)  &&  NOW.year==( (NOW.year/4) * 4) )
  dayCount=29;//works for any year within the next 3 centuries at least

diff.second = TARGET.second - NOW.second;
if (diff.second < 0)
  {
   diff.second = 60 + diff.second;
   NOW.minute++;
  }

diff.minute = TARGET.minute - NOW.minute;
if (diff.minute < 0)
  {
   diff.minute = 60 + diff.minute;
   NOW.hour++;
  }

diff.hour = TARGET.hour - NOW.hour;
if (diff.hour < 0)
  {
   diff.hour = 24 + diff.hour;
   NOW.day++;
  }

diff.day = TARGET.day - NOW.day;
if (diff.day < 0)
  {
   diff.day = dayCount + diff.day;
   NOW.month++;
  }

diff.month = TARGET.month - NOW.month;
if (diff.month < 0)
  {
   diff.month = 12 + diff.month;
   NOW.year ++;
  }

diff.year = TARGET.year - NOW.year;
if (diff.year < 0)
  diff=(plainDT){0,0,0,0,0,0};

sprintf(diffString,"%04d %02d %02d %02d:%02d:%02d",diff.year, diff.month, diff.day, diff.hour, diff.minute, diff.second);
}

weedpharma:
I have not read the code. I wonder why this countdown display part is difficult given that you have successfully done all the other part.

Please explain what the difficulty is.

Calculate days remaining
Position cursor
Output the value

Weedpharma

the difficulty is i do not know how to set the target time, and make the program counts the amount of days left. do you understand me ?

thanks for replying though :slight_smile:

weedpharma:
I have not read the code. I wonder why this countdown display part is difficult given that you have successfully done all the other part.

Please explain what the difficulty is.

Calculate days remaining
Position cursor
Output the value

Weedpharma

hey there, i've tried compiling your coding, thank you so much for it. but i'm not quite sure though what's that on the last line. hope you can explain.

really appreciate your help, thank you so much

I think your last was meant for KenF.

However I'm happy to take credit for someone else's work. :))

Weedpharma

weedpharma:
I think your last was meant for KenF.

However I'm happy to take credit for someone else's work. :))

Weedpharma

No I think this is the code she's trying to compile

Calculate days remaining
Position cursor
Output the value

Weedpharma

She doesn't know what the command "weedpharma" means. I suspect it's causing a syntax error :wink: