Hi
needing a little help to be able to change the readout to a 12 hour format.
thx in advance
// LiquidCrystal I2C - Version: Latest
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <ds3231.h>
#define BUFF_MAX 128
//****************************************Define I2C LCD Display *********************************
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal_I2C lcd(0x27, 16, 2);
//************************************ END LCD DISPLAY *******************************************
uint8_t time[8];
char recv[BUFF_MAX];
unsigned int recv_size = 0;
unsigned long prev, interval = 1000;
int led = 13;
void setup()
{
Serial.begin(9600);
Wire.begin();
DS3231_init(DS3231_INTCN);
memset(recv, 0, BUFF_MAX);
Serial.println("GET time");
//LCD Setup******
lcd.begin(16, 2); // initialize the lcd
// Switch on the backlight
// lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
// lcd.setBacklight(LED_ON);
lcd.backlight();
//END LCD Setup*****
lcd.print("Setting time");
delay(2000);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Hello World");
delay(2000);
lcd.clear();
lcd.print("Setting Date");
delay(2000);
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Ready..Set..Go..");
//setTheTime("001220316102019"); // ssmmhhWDDMMYYYY set time once in the given format
}
void loop()
{
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a 1/2 second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a 1/2 second
char tempF[6];
float temperature;
char buff[BUFF_MAX];
unsigned long now = millis();
struct ts t;
// show time once in a while
if (now - prev > interval) {
DS3231_get(&t); //Get time
temperature = DS3231_get_treg(); //Get temperature (tempF × 9/5) + 32
temperature = temperature * 9/5 + 32;
dtostrf(temperature, 5, 1, tempF);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(t.mday);
printMonth(t.mon);
lcd.print(t.year);
lcd.setCursor(0, 1); //Go to second line of the LCD Screen
lcd.print(t.hour);
lcd.print(":");
lcd.print(t.min);
lcd.print(":");
if (t.sec < 10)
{
lcd.print("0");
}
lcd.print(t.sec);
lcd.print(' ');
lcd.setCursor(9, 1);
lcd.print(tempF);
lcd.print((char)223);
lcd.print("F");
prev = now;
}
}
void setTheTime(char *cmd)
{
struct ts t;
// ssmmhhWDDMMYYYY set time
t.sec = inp2toi(cmd, 0);
t.min = inp2toi(cmd, 2);
t.hour = inp2toi(cmd, 4);
t.wday = inp2toi(cmd, 6);
t.mday = inp2toi(cmd, 7);
t.mon = inp2toi(cmd, 9);
t.year = inp2toi(cmd, 11) * 100 + inp2toi(cmd, 13);
DS3231_set(t);
Serial.println("OK");
}
void printMonth(int month)
{
switch (month)
{
case 1: lcd.print(" January "); break;
case 2: lcd.print(" February "); break;
case 3: lcd.print(" March "); break;
case 4: lcd.print(" April "); break;
case 5: lcd.print(" May "); break;
case 6: lcd.print(" June "); break;
case 7: lcd.print(" July "); break;
case 8: lcd.print(" August "); break;
case 9: lcd.print(" September"); break;
case 10: lcd.print(" October "); break;
case 11: lcd.print(" November "); break;
case 12: lcd.print(" December "); break;
default: lcd.print(" Error "); break;
}
}