// https://wokwi.com/projects/386388559346728961
#include <SevenSeg.h>
#include "RTClib.h"
// Initialize the RTC object and two SevenSeg objects.
RTC_DS1307 rtc;
SevenSeg disp(3,4,5,6,7,8,9); // a,b,c,d,e,f,g SevenSeg disp(2,3,4,5,6,7,8);
SevenSeg disp1(3,4,5,6,7,8,9); // a,b,c,d,e,f,g SevenSeg disp1(2,3,4,5,6,7,8);
// Constants and arrays for digit pins
const int numOfDigits = 4;
int digitPins[numOfDigits]={ 13,12,11,10}; // { 13,12,11,10}; // { 12,11,10,9};
int digitPins1[2]={A0, A1}; // int digitPins1[2] = {A2, A3};
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// Include the required Arduino libraries:
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
// Define hardware type, size, and output pins:
#define HARDWARE_TYPE1 MD_MAX72XX::PAROLA_HW//::FC16_HW
#define MAX_DEVICES1 4
#define CS_PIN1 1 // CS 9 1 4 7 10
// Create a new instance of the MD_Parola class with hardware SPI connection:
//MD_Parola myDisplay = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Setup for software SPI:
#define DATA_PIN1 0 // DIN 8 0 3 6 9
#define CLK_PIN1 2 // CLK 10 2 5 8 11
MD_Parola myDisplay1 = MD_Parola(HARDWARE_TYPE1, DATA_PIN1, CLK_PIN1, CS_PIN1, MAX_DEVICES1);
// // // // // // // // // // // // // // // // // // // //
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
void setup() {
// Pin-digit set for each SevenSeg
disp.setDigitPins(numOfDigits, digitPins);
disp1.setDigitPins(2, digitPins1);
// Initialize RTC
if (!rtc.begin()) {
Serial.println("Cannot find RTC");
while (1)
delay(10);
}
// Check if RTC is running, if not, set default time
if (!rtc.isrunning()) {
Serial.println("RTC is not running");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// Intialize the object:
myDisplay1.begin();
// Set the intensity (brightness) of the display (0-15):
myDisplay1.setIntensity(0);
// Clear the display:
myDisplay1.displayClear();
// // // // // // // // // // // // // // // // // // // //
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
}
void loop() {
// Get the current time from RTC
DateTime now = rtc.now();
// Calculate time in hours and minutes format
//float jam = (now.hour() * 100) + now.minute();
// Show the clock on SevenSeg first
disp1.writeClock(now.hour());
disp1.clearDisp();
// Display minutes and seconds on the second SevenSeg
disp.writeClock(now.minute(), now.second());
disp.clearDisp();
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
myDisplay1.setTextAlignment(PA_CENTER);
myDisplay1.print("BATAM"); // myDisplay1.print("Center");
delay(1);
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
}