Clock and text in a sequence and displaying one digit from an hour

Hello,

I've build a simple clock with LCD display and RTC1302 module. I want my clock to display time for a minute and then text for another one (actually it is a text combined with a timer). It is supposed to change with the :00 in seconds timer. I thought it would be easy to code it, but I'm encountering some difficulties. I've tried to learn the millis function or changing the value on delay function, but each time either the clock stops or the whole text disappears. For now it just changes with each second. I'm a super newbie and it might be a very easy question, but would be really grateful for the explanation.

Second task is a bit more unusual. I consider it a next step after figuring out the timeline issue. I want to display something that pretends to be a glitch, so as I have the following format for time: HH:MM:SS (in sprintf function %02:%02:%02), I want to change it to: (letter)H:M(letter):SS. The letter would be constant, but I just want the first digit from hours and second digit from minutes. Is that even possible? Just an aesthetic choice, nothing functional.

#include "virtuabotixRTC.h"//Library used
#include <LiquidCrystal_I2C.h>
 
LiquidCrystal_I2C lcd(0x27, 16, 2);
virtuabotixRTC myRTC(2, 3, 4); //The order here is DAT,CLK,RST. You can change this depending on the wiring

char timeChar [8]; //number of digits for the format

const unsigned long eventInterval = 60000;
unsigned long previousTime = 0;
 
void setup() {

Serial.begin(9600);
 
lcd.init();
lcd.backlight();
 
// Set the current date, and time in the following format:
// seconds, minutes, hours, day of the week, day of the month, month, year
//myRTC.setDS1302Time(00, 02, 13, 2, 7, 12, 2021); //Here you write your actual time/date as shown above
//but remember to "comment/remove" this function once you're done
//The setup is done only one time and the module will continue counting it automatically
}
void loop() {

  myRTC.updateTime();


    // Start printing elements as individuals
    lcd.setCursor(6,0);
    lcd.print("TIME");
    
    lcd.setCursor(4,1);
    sprintf(timeChar, "%02d:%02d:%02d",myRTC.hours, myRTC.minutes, myRTC.seconds);
    lcd.print(timeChar);
    delay(1000);
    

    lcd.setCursor(6,0);
    lcd.print("TIME");
    
    lcd.setCursor(4,1);
    sprintf(timeChar, "D0:0M:%02d", myRTC.seconds);
    lcd.print(timeChar);
    delay(1000);

   
  }

Not tested with your RTC library but is this what your looking for...

#include "virtuabotixRTC.h"//Library used
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);
virtuabotixRTC myRTC(2, 3, 4); //The order here is DAT,CLK,RST. You can change this depending on the wiring

char timeChar [8]; //number of digits for the format
uint8_t prevSeconds = 0; //

void setup() 
{
  
  Serial.begin(9600);
  
  lcd.init();
  lcd.backlight();
  
  // Set the current date, and time in the following format:
  // seconds, minutes, hours, day of the week, day of the month, month, year
  //myRTC.setDS1302Time(00, 02, 13, 2, 7, 12, 2021); //Here you write your actual time/date as shown above
  //but remember to "comment/remove" this function once you're done
  //The setup is done only one time and the module will continue counting it automatically
}
void loop() 
{
  
  myRTC.updateTime();
  
  if(myRTC.seconds != prevSeconds)  // Only update display if seconds have changed
  {
    prevSeconds = myRTC.seconds;
    
    // Start printing elements as individuals
    lcd.setCursor(6,0);
    lcd.print("TIME");
    lcd.setCursor(4,1);
    
    if(myRTC.minute() % 2)
    {
      sprintf(timeChar, "%02d:%02d:%02d",myRTC.hours, myRTC.minutes, myRTC.seconds);
    }
    else
    {
      sprintf(timeChar, "D0:0M:%02d", myRTC.seconds);
    }
    
    lcd.print(timeChar);
  }
}
1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.