MD_Parola.h and MD_DS1307.h Clock Help!

I am working on a clock and temperature plus humidity module.

Followed already posted examples , and helps me alot , but the issue is time and date setting of ds1307 with button.

I am still on newbie stage with md_parola.h So please give me an example code that can help me or teach me enough about md_ds1307 setting control using md_parola

Here is my modified code to display the time and date !

#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <MD_DS1307.h>
#include <Wire.h>
#if USE_LIBRARY_SPI
#include <SPI.h>
#endif

// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may 
// need to be adapted
#define	MAX_DEVICES	4
#define	CLK_PIN		13
#define	DATA_PIN	11
#define	CS_PIN		10

// Hardware SPI connection
MD_Parola P = MD_Parola(CS_PIN, MAX_DEVICES);
// Arbitrary output pins
// MD_Parola P = MD_Parola(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
#define BUF_SIZE  100
char curMessage[BUF_SIZE];
char  szTime[9];
char  szDate[20];
uint8_t  curText;

char *mon2str(uint8_t mon, char *psz, uint8_t len)

// Get a label from PROGMEM into a char array
{
  static const __FlashStringHelper*  str[] = 
  {
    F("Jan"), F("Feb"), F("Mar"), F("Apr"), 
    F("May"), F("Jun"), F("Jul"), F("Aug"), 
    F("Sep"), F("Oct"), F("Nov"), F("Dec")
  };

  strncpy_P(psz, (const char PROGMEM *)str[mon-1], len);
  psz[len] = '\0';

  return(psz);
}

char  *pc[] =
{
  " ",
  szDate,

  curMessage,
};

#define  SPEED_TIME  10
#define PAUSE_TIME  1000

uint8_t  inFX, outFX;
textEffect_t  effect[] =
{
 PRINT,
 SCROLL_LEFT,
  /*MD_Parola::WIPE,
  MD_Parola::SCROLL_UP,
  MD_Parola::OPENING_CURSOR,
  MD_Parola::BLINDS,
  MD_Parola::CLOSING,
  MD_Parola::WIPE_CURSOR,
  MD_Parola::DISSOLVE,
  MD_Parola::OPENING,
  MD_Parola::CLOSING_CURSOR,
  MD_Parola::SCROLL_RIGHT,
  MD_Parola::SCROLL_DOWN,*/
  SLICE,
};


void getTime(char *psz, bool f = true)
// Code for reading clock time
{

  RTC.readTime();
sprintf(psz, "%02d%c%02d", RTC.h, (f ? '\xd8' : ' '), RTC.m);
//sprintf(psz, "%02d%c%02d", RTC.h, ':', RTC.m);
}


void getDate(char *psz)
// Code for reading clock date
{

  char  szBuf[10];
  
  RTC.readTime();
  sprintf(psz, "%d %s", RTC.dd, mon2str(RTC.mm, szBuf, sizeof(szBuf)-1));
}

void setup(void)
{
  P.begin();
  P.setInvert(false);
  
   P.displayText(szTime, CENTER, SPEED_TIME, PAUSE_TIME, effect[inFX], effect[outFX]);
   RTC.control(DS1307_CLOCK_HALT, DS1307_OFF);
   RTC.control(DS1307_12H, DS1307_ON);

getTime(szTime);
  
}

void loop(void)
{
   static uint32_t  lastTime = 0;   // millis() memory
  RTC.readTime();
  uint8_t mins = 50;
  static bool flasher = false;  // seconds passing flasher
 
 if (P.displayAnimate()){
if (RTC.m != mins){

  P.setTextEffect(PRINT, NO_EFFECT);
// Finally, adjust the time string if we have to
  if (millis() - lastTime >= 1000)
  {
    lastTime = millis();
    getTime(szTime, flasher);
    flasher = !flasher; 
  }
  
 curText = (++curText) % ARRAY_SIZE(pc);
    P.setTextBuffer(szTime);
   P.displayReset();
 
}
       if (RTC.m == mins){
        if (millis() - lastTime >= 1000)
        {
           lastTime = millis();
            getDate(szDate);
          }
  
            curText = (++curText) % ARRAY_SIZE(pc);
             P.setTextBuffer(pc[curText]);
   
          outFX = (++outFX) % ARRAY_SIZE(effect);
           if (outFX == 0)
            {
                inFX = (++inFX) % ARRAY_SIZE(effect);
               }
 
             P.setTextEffect(effect[inFX], effect[outFX]);
        P.displayReset();
 
          }
    }
  }

I tried to update only the mins but it is not updating correctly.

Here is my sketch with button routine

// Program to demonstrate the MD_Parola library
//
// Simplest program that does something useful - Hello World!

#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <MD_DS1307.h>
#include <Button.h>                      // Button library by Alexander Brevig
#include <Wire.h>
#if USE_LIBRARY_SPI
#include <SPI.h>
#endif

// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may 
// need to be adapted
#define	MAX_DEVICES	4
#define	CLK_PIN		13
#define	DATA_PIN	11
#define	CS_PIN		10

Button buttonA = Button(2, BUTTON_PULLUP);      // Setup button A (using button library)
Button buttonB = Button(3, BUTTON_PULLUP);      // Setup button B (using button library)
// Hardware SPI connection
MD_Parola P = MD_Parola(CS_PIN, MAX_DEVICES);
// Arbitrary output pins
// MD_Parola P = MD_Parola(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
#define BUF_SIZE  100
char curMessage[BUF_SIZE];
char  szTime[9];
char  szDate[20];
char  szMin[5];
uint8_t  curText;

char *mon2str(uint8_t mon, char *psz, uint8_t len)

// Get a label from PROGMEM into a char array
{
  static const __FlashStringHelper*  str[] = 
  {
    F("Jan"), F("Feb"), F("Mar"), F("Apr"), 
    F("May"), F("Jun"), F("Jul"), F("Aug"), 
    F("Sep"), F("Oct"), F("Nov"), F("Dec")
  };

  strncpy_P(psz, (const char PROGMEM *)str[mon-1], len);
  psz[len] = '\0';

  return(psz);
}

char  *pc[] =
{
  " ",
  szDate,

  curMessage,
};
//char  szTime[20] = {""};
#define  SPEED_TIME  10
#define PAUSE_TIME  1000

uint8_t  inFX, outFX;
textEffect_t  effect[] =
{
 PRINT,
 SCROLL_LEFT,
  /*MD_Parola::WIPE,
  MD_Parola::SCROLL_UP,
  MD_Parola::OPENING_CURSOR,
  MD_Parola::BLINDS,
  MD_Parola::CLOSING,
  MD_Parola::WIPE_CURSOR,
  MD_Parola::DISSOLVE,
  MD_Parola::OPENING,
  MD_Parola::CLOSING_CURSOR,
  MD_Parola::SCROLL_RIGHT,
  MD_Parola::SCROLL_DOWN,*/
  SLICE,
};


void getTime(char *psz, bool f = true)
// Code for reading clock time
{

  RTC.readTime();
sprintf(psz, "%02d%c%02d", RTC.h, (f ? '\xd8' : ' '), RTC.m);
//sprintf(psz, "%02d%c%02d", RTC.h, ':', RTC.m);
}

void getMin(char *psz, bool f = true)
// Code for reading clock time
{

  RTC.readTime();
sprintf(psz, "%02d",  RTC.m);

}

void getDate(char *psz)
// Code for reading clock date
{

  char  szBuf[10];
  
  RTC.readTime();
  sprintf(psz, "%d %s", RTC.dd, mon2str(RTC.mm, szBuf, sizeof(szBuf)-1));
}

void setup(void)
{
  P.begin();
  P.setInvert(false);
 digitalWrite(2, HIGH);                 // turn on pullup resistor for button on pin 2
 digitalWrite(3, HIGH);                 // turn on pullup resistor for button on pin 3
 
// RTC.h = 10;
  // RTC.writeTime(); 
  
 
   P.displayText(szTime, CENTER, SPEED_TIME, PAUSE_TIME, effect[inFX], effect[outFX]);
   RTC.control(DS1307_CLOCK_HALT, DS1307_OFF);
   RTC.control(DS1307_12H, DS1307_ON);

getTime(szTime);
  
}

void loop(void)
{
   static uint32_t  lastTime = 0;   // millis() memory
  RTC.readTime();
  uint8_t mins = 50;
  static bool flasher = false;  // seconds passing flasher
 
 if (P.displayAnimate()){
if (RTC.m != mins){

  P.setTextEffect(PRINT, NO_EFFECT);
// Finally, adjust the time string if we have to
  if (millis() - lastTime >= 1000)
  {
    lastTime = millis();
    getTime(szTime, flasher);
    flasher = !flasher; 
  }
  
   if (buttonA.isPressed()) {
      sett();
      return;
    }
 curText = (++curText) % ARRAY_SIZE(pc);
    P.setTextBuffer(szTime);
   P.displayReset();
 
}
       if (RTC.m == mins){
        if (millis() - lastTime >= 1000)
        {
           lastTime = millis();
            getDate(szDate);
          }
  
            curText = (++curText) % ARRAY_SIZE(pc);
             P.setTextBuffer(pc[curText]);
   
          outFX = (++outFX) % ARRAY_SIZE(effect);
           if (outFX == 0)
            {
                inFX = (++inFX) % ARRAY_SIZE(effect);
               }
 
             P.setTextEffect(effect[inFX], effect[outFX]);
        P.displayReset();
 
          }
    }
  }

  void sett()
  {
    
   
    static uint32_t  lastTime = 0;   // millis() memory
    //loop waiting for button 
   
      
      
      P.setTextEffect(PRINT, NO_EFFECT);
// Finally, adjust the time string if we have to
   if (millis() - lastTime >= 1000)
  {
    lastTime = millis();
    getMin(szMin);
    
  }
   
  // curText = (++curText) % ARRAY_SIZE(pc);
    P.setTextBuffer(szMin);
   P.displayReset();

    while (buttonB.isPressed()){
    RTC.readTime();
    uint8_t mins = 0;
    if (RTC.m != mins){
mins++;
  RTC.m = mins;
   RTC.writeTime(); 
    }
 
      
    }
 
    
  
    }

When I did a project for a WordClock I did an update button for the time as part of that project. You could look at that code to see how I did it there. You will need to adapt what was done, but the principles remain the same.

Sketch for the WordClock are from my library site, link below, and I also have an article on the blog.

marco_c:
When I did a project for a WordClock I did an update button for the time as part of that project. You could look at that code to see how I did it there. You will need to adapt what was done, but the principles remain the same.

Sketch for the WordClock are from my library site, link below, and I also have an article on the blog.

its a very healthy code :frowning:
Please give me an example where i can learn and after learning i can adopt the routine

There is only one function in there you need to find. The code is not that big and the description at the top tells you how it works (functionally). The function will be called setTime or something similar - it should not be that hard to find.

I really don't have time to 'adapt' a function for you.

As I thought, It was called setupTime. You need to look at the rest of the sketch for any libraries or definitions that are missing here and substitute the 'time' printing code with something else for your own displays.

void setupTime(uint8_t &h, uint8_t &m)
// Handle the user interface to set the current time.
// Remains in this function until completed.
{
  uint32_t  timeLastActivity = millis();
  uint8_t map[FONT_ROWS];
  stateSetup_t state = SS_DISP_HOUR;

  while (state != SS_END)
  {
    // check if we time out
    if (millis() - timeLastActivity >= SETUP_TIMEOUT)
    {
      PRINTS("\nSetup inactivity timeout");
      state = SS_END;
    }

    // process current state
    switch (state)
    {
    case SS_DISP_HOUR:   // show the hour
      mapBuild(map, h);
      mapShow(map);
      state = SS_HOUR;
      break;

    case SS_HOUR:   // handle setting hours
      switch (swMode.read())
      {
      case MD_KeySwitch::KS_DPRESS:   // move on to minutes
        timeLastActivity = millis();
        state = SS_DISP_MIN;
        break;
      case MD_KeySwitch::KS_PRESS:    // increment the hours
        timeLastActivity = millis();
        h++;
        if (h == 13) h = 1;
        state = SS_DISP_HOUR;
        break;
      }
      break;

    case SS_DISP_MIN:   // show the minutes
      mapBuild(map, m);
      mapShow(map);
      state = SS_MIN;
      break;

    case SS_MIN:   // handle setting minutes
      switch (swMode.read())
      {
      case MD_KeySwitch::KS_DPRESS:   // move on to end
        timeLastActivity = millis();
        state = SS_END;
        break;
      case MD_KeySwitch::KS_PRESS:    // increment the minutes
        timeLastActivity = millis();
        m = (m + 1) % 60;
        state = SS_DISP_MIN;
        mapShow(map);
        break;
      }
      break;

    default:  // our work is done
      state = SS_END;
    }
  }
}

:) many thanks for the help, I sorted out old button.h library to work with :)

Thanks once again for the help