Alright, I'm making an LCD clock using a DS1307 micro controller. The clock works perfectly fine as is, but I would like to add a 12 hour functionality to it. I'm aware the command used to make this happen is "hourFormat12();" although I'm not exactly sure where to implement it into my code (as replacing the tm.hours makes it a constant 12 o'clock).
#include <LiquidCrystal.h>
#include <DS1307RTC.h>
#include <Time.h>
#include <Wire.h>
LiquidCrystal lcd(9, 10, 5, 8, 7, 6); //Change these pins in relation to your LCD (First pin = leftmost pin on LCD Screen)
const char *monthName[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
tmElements_t tm;
int twelve = hourFormat12();
void setup() {
Serial.begin(9600);
while (!Serial) ; // wait for serial
delay(200);
Serial.println("-------------------");
Serial.println("| Serial For Clock |");
Serial.println("-------------------");
lcd.setCursor(0, 0);
lcd.begin(16, 2);
bool parse=false;
bool config=false;
}
void loop() {
tmElements_t tm;
if (RTC.read(tm)) {
Serial.print("Time: ");
print2digits(tm.Hour);
Serial.write(':');
print2digits(tm.Minute);
Serial.write(':');
print2digits(tm.Second);
Serial.print(" Date: ");
Serial.print(tm.Day);
Serial.write('/');
Serial.print(tm.Month);
Serial.write('/');
Serial.print(tmYearToCalendar(tm.Year));
Serial.println();
}
else {
if (RTC.chipPresent())
{
Serial.println("The DS1307 is off.");
delay(9000); }
}
lcd.print("T: ");
lcd.print(tm.Hour);
lcd.print(":");
lcd.print(tm.Minute);
lcd.print(":");
lcd.print(tm.Second);
lcd.setCursor(0, 1);
lcd.print("D: ");
lcd.print(tm.Day);
lcd.print("/");
lcd.print(tm.Month);
lcd.print("/");
lcd.print(tmYearToCalendar(tm.Year));
delay(1000);
lcd.clear();
}
void print2digits(int number)
{
if (number >= 0 && number < 10)
{
Serial.write('0');
}
Serial.print(number);}
bool getTime(const char *str)
{
int Hour, Min, Sec;
if (sscanf(str, "%d:%d:%d", &Hour, &Min, &Sec) != 3) return false;
tm.Hour = Hour;
tm.Minute = Min;
tm.Second = Sec;
return true;
}
bool getDate(const char *str)
{
char Month[12];
int Day, Year;
uint8_t monthIndex;
if (sscanf(str, "%s %d %d", Month, &Day, &Year) != 3) return false;
for (monthIndex = 0; monthIndex < 12; monthIndex++)
{
if (strcmp(Month, monthName[monthIndex]) == 0) break;
}
if (monthIndex >= 12) return false;
tm.Day = Day;
tm.Month = monthIndex + 1;
tm.Year = CalendarYrToTm(Year);
return true;
}
Any help is greatly appreciated, I have looked through other help threads and across google; but most examples I found either wouldnt work with my current code or didn't explain the process clearly.