#include"ADC.h"
#include"RTC.h"

#include<string.h>
#include<math.h>
/*
void setup()
{
  char str[16]={0};
 float temp;
   LCD_init();
   ADC_init();
   RTC_address(sec,mints,hrs,dt,mnth,yr);
   
  Serial.print(str);
    while(1)
           {
            Serial.println("va");
            GET_TIME_DATE();
            delay(10);
             temp = convertToCelcius(AnalogRead());
             sprintf(str,"Temp: %.2d C",(uint16_t)temp);
             printTimeToLcd();
             LCD_cmd(0x80);
             LCD_string(str);
             delay(1000);
             LCD_clear();
              LCD_cmd(0x80);
             LCD_string(TIME);
              LCD_cmd(0xc0);
             LCD_string(DATE);
             delay(2000);
             LCD_clear();
            }  
}

void loop()
{
}
*/
void delay1(int a) //a = 400 ---> 1 second (approximately) 
{
   volatile long i; 
   while(a)
   {
     for(i = 1;i<=1000;i++);
     a--;
   }
}

void setup()
{
  i2c_init();         
  Lcd_init();
  ADC_init();
  rtc_init(initial_seconds,initial_minutes,initial_hours,initial_date,initial_month,initial_year);  
  
}

void loop()                 //runs continuosly
{
   getCurrentDateTime();
   printTimeToLcd();
   tempResult = convertToCelcius(AnalogRead());
   sprintf(str,"Temperature: %02d C",(uint16_t)tempResult);  //converting temperature result to string
   if(current_seconds%10 == 0||current_seconds%10 == 1||current_seconds%10 == 9)               //storing and displaying the temperature data for 10|9|11 seconds once
   {
      //writeToSDcard(date_arr,time_arr,str);   //writing to SD card along with time stamp
      Lcd_sendCommand(0x94);
      Lcd_sendString(str);
   }
   delay1(400);        //1 sec delay
   //readFromSDcard();  //used to read stored data from SD card
}
GND5VSDASCLSQWRTCDS1307+