1

Good morning, I am coding an alarm clock on arduino by using a DS3231 and a TM1638. The code works and the time updates in the serial monitor,although the time doesn't update on the tm1638. I'll attach the code here:

#include <DS3231.h>  
#include <TM1638.h> 
#include <Streaming.h>  
#include <SPI.h>  
#include <Wire.h>  
#include <InvertedTM1638.h>  
#include <TM1638.h>  
#include <TM1638QYF.h>  
#include <TM1640.h>  
#include <TM16XX.h>  
#include <TM16XXFonts.h>  
byte buttons;  
#define TM1638_STB D5  
#define TM1638_CLK D6  
#define TM1638_DIO D7  

TM1638 module(TM1638_DIO, TM1638_CLK, TM1638_STB);  
// DS3231 uses I2C - device ID 0x68  
// on Wemos mini pins SDA -> D1 and SCL -> D2  
DS3231 rtc;  
int hours;  
int minutes;  
int seconds;  
bool h12; 
bool PM;  
int data; 
RifTime t;  
char buffer[24];  

void setup()  
{  
  // set up the 7-segment display 
  module.clearDisplay();  
  module.setupDisplay(true, 2);  
  Wire.begin();  
  Serial.begin(115200);  

  Serial.println(F("\nDS3231 Hi Precision Real Time Clock"));  

  // Fill these variables with the date and time.  
  int seconds, minutes, hours, dayofweek, dayofmonth, month, year;  

  // Example for april 15, 2013, 10:08, monday is 2nd day of Week.  
  // Set your own time and date in these variables.  
  // dayofweek = 4; // Day of week, any day can be first, counts 1...7  
  hours = 14; 
  minutes = 30;  
  seconds = 0;  
  year = 2019;  
  month = 8; // month 1...12  
  dayofmonth = 28; // Day of month, 1...31  

  data=( hours * 10000 + minutes * 100 + seconds * 1 ); 

  rtc.setClock(year,month,dayofmonth,hours,minutes,seconds);  
} 

void loop()  
{  
  rtc.getTime(t);  
  Serial << rtc.toString(buffer) << endl;

  delay(1000); // do nothing  

  module.setDisplayToDecNumber(data,4,false);  

  if(seconds==60) 
  { 
    seconds=00; 
    minutes++; 
  } 
  if(minutes==60)
  {
    minutes=0;
    hours++;
  }

  if(hours==24) 
  { 
    data=00000000; 
  } 

  if((data)==143000) 
  { 
    module.setLEDs(0x0001); 
  } 
  else
  {
    module.setLEDs(0x0000);
  }

}
2

You set the variable data only in the setup function.

You also do not print out data to Serial but the output of rtc.toString(buffer).

If data is not updated in the loop method, the display constantly shows the time you initially set in the setup method.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.