Can't get lcd.print to work with library functions

Hi! So I am trying to print a time in 12 hour format as well as the date in m/d/y format using a library I found. I have the code down for printing to Serial but now I want to print it to my LCD. Here is how I left my code: (Part I’m having trouble with is after loop()) - “lcd.print(Clock.print12HourTimeTo_HM());”

#include <LiquidCrystal.h>
#include <DS3231_Simple.h>

DS3231_Simple Clock;
int buzzer = 4;//the pin of the active buzzer
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup() {

  pinMode(buzzer, OUTPUT); //initialize the buzzer pin as an output
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  Serial.begin(9600);
  Clock.begin();

  // We will set 2 alarms, the first alarm will fire at the 30th second of every minute
  //  and the second alarm will fire every minute (at the 0th second)

  // First we will disable any existing alarms
  Clock.disableAlarms();

  // Get an initialized timestamp
  DateTime MyTimestamp = Clock.read();

  // We want the alarm at this second
  MyTimestamp.Second = 00;
  MyTimestamp.Minute = 21;
  MyTimestamp.Hour = 17;




  // We will set the second alarm to match every minute, since there's
  // no specific time/date data necessary for that we don't have to
  // supply any (but you could if you wanted just like the above).
  Clock.setAlarm(MyTimestamp, DS3231_Simple::ALARM_MATCH_SECOND_MINUTE_HOUR);

  // See comments at bottom of file for more alarm types!

  Serial.println("Waiting for alarms...");

}

void loop()
{
  DateTime MyDateAndTime;

  // Ask the clock for the data.
  MyDateAndTime = Clock.read();
  lcd.setCursor(4, 0);
  lcd.print(Clock.print12HourTimeTo_HM());
  lcd.setCursor(2, 1);
  lcd.print(Clock.printDateTo_MDY());
  // To check the alarms we just ask the clock
  uint8_t AlarmsFired = Clock.checkAlarms();

  // Then can check if either alarm is fired (there are 2 alarms possible in the chip)
  // by using a "bitwise and"
  if (AlarmsFired & 1)
  {
    Clock.printTo(Serial); Serial.println(": It is: ");
    unsigned char i;
    //output an frequency
    for (i = 0; i < 100; i++)
    {
      digitalWrite(buzzer, HIGH);
      delay(10);//wait for 1ms
      digitalWrite(buzzer, LOW);
      delay(10);//wait for 1ms
    }
  }
  while (1);

}

I have also tried this:

  Clock.print12HourTimeTo_HM(Serial);
  Clock.printDateTo_MDY(Serial);

//That works but this does NOT:

  Clock.print12HourTimeTo_HM(lcd.print);
  Clock.printDateTo_MDY(lcd.print);

I have also tried: lcd.print(Clock.print12HourTimeTo_HM(MyDateAndTime)); but still no joy.

Thanks! I am still new to this whole experience!

Did you have to use "Clock.printDateTo_MDY(Serial.print)" to print to serial? No, you didn't. Try using "Clock.printDateTo_MDY(lcd)" instead of "Clock.printDateTo_MDY(lcd.print)".

I tried that as well:

C:\Users\user\Documents\Arduino\libraries\DS3231_Simple/DS3231_Simple.h:277:14: note:   no known conversion for argument 1 from 'LiquidCrystal' to 'Stream&'

Using library LiquidCrystal at version 1.0.7 in folder: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal 
Using library DS3231_Simple in folder: C:\Users\user\Documents\Arduino\libraries\DS3231_Simple (legacy)
Using library Wire at version 1.0 in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\Wire 
exit status 1
no matching function for call to 'DS3231_Simple::print12HourTimeTo_HM(LiquidCrystal&)'

That was one of the first things I tried.

Clock.print12HourTimeTo_HM() requires a pointer to a Stream class. Serial is an object of HardwareSerial class which is inherited from Stream class which inherited from Print class. lcd is an object of LiquidCrystal class which is inherited from Print class.

In other words, there is no short cut. You have to to what you need to hard way. The DS3231_Simple library has a read() which return a DateTime. Try to display the DateTime to your lcd instead.

Yes but I would like to format it in that particular format. when I used DateTime before it only gave me the default format. Do you have an idea about how I can get it in 12hr format using DateTime?

Thanks!

If you can get the second, minute, hour, year, ect., you can use sprintf() to format your desired cstring. It should look like this:

char dt[30];
int m, d, y;
//get m, d, y
sprintf(dt, "%02d/%02d/%04d", m, d, y);
lcd.print(dt);

or you can just print directly to the lcd.

Ok, great! Thanks! I will try it out shortly. - Out of curiosity: What does this refer to? "%02d/%02d/%04d" Is it a built in library or what? Where would I go for more code like that?

AdamHFF:
Ok, great! Thanks! I will try it out shortly. - Out of curiosity: What does this refer to? “%02d/%02d/%04d” Is it a built in library or what? Where would I go for more code like that?

Read it here

What is the dt array with 30 elements for? To print directly to lcd would i just substitute lcd.print into sprintf?

arduino_new: char dt[30]; int m, d, y; //get m, d, y sprintf(dt, "%02d/%02d/%04d", m, d, y); lcd.print(dt);

or you can just print directly to the lcd.

Thanks!

Doing some more looking, I found that I couldnt print to lcd with that because it only takes 1 argument at a time. so sprintf is just to get it all in a string, right? I can then print the string with lcd.print - but still - why 30 elements to the array? wouldnt it only need 4? 2 digits for hour 2 for minute - then another one with 2 for day 2 for month and 4 for year?

The '/' characters also require storage space. Plus the terminating '\0' that's required. Don't obsess about the 30 so much. Just make the buffer bigger than the maximum you think is required.

As @gfvalvo said, 30 is just arbitrary choice. With your format: 00/00/0000 you only need 11 space in fact.