/*
Use of MAX72XX, DS1307 and DTH22 components to
print some information on the display.
for more examples:
https://github.com/MajicDesigns/MD_Parola/tree/main/examples
https://github.com/MajicDesigns/MD_MAX72XX/tree/main/examples
*/
// Header file includes
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <Wire.h>
#include "ya_font_data.h"
#include "SholahTimeCalulation.h"
// 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 HARDWARE_TYPE MD_MAX72XX::PAROLA_HW
#define MAX_DEVICES 8 // Define the number of displays connected
#define CLK_PIN 13 // CLK or SCK
#define DATA_PIN 11 // DATA or MOSI
#define CS_PIN 10 // CS or SS
#define SPEED_TIME 75 // Speed of the transition
#define PAUSE_TIME 0
#define MAX_MESG 20
// These are for the clock
#define DS1307_ADDRESS 0x68
String str_waktu_sholat;
const char namaWaktuSholat[8][12] PROGMEM = { "Imsak ", " Subuh ", " Terbit ", " Dhuha ", " Dzuhur ", " Ashar ", " Maghrib ", " Isya " };
const char pasar[5][7] = { "Wage", "Kliwon", "Legi", "Pahing", "Pon" };
String waktu_tbt, waktu_dhu, waktu_sbh, waktu_dzr, waktu_ims, waktu_asr, waktu_mgr, waktu_isy;
String txhh, txmm, txss, cck;
int mode = 0;
int ash;
int j_s_s = 0;
String slt_sek;
byte wkt_msk_skrg = 0;
int durasi_tampil_adzan;
int iqm_ee, sis_wkt_iqo, du_iq, iqm_menit, iqm_menit_sisa, iqm_detik;
String wkt_iqomah, tpl_iqo_ss, textIqohitmun, wkt_ims_sat;
String pesan;
// Global variables
uint8_t wday, mday, month, year;
uint8_t hours, minutes, seconds;
char szTime[9]; // mm:ss\0
char szMesg[MAX_MESG + 1] = "";
uint8_t clear = 0x00;
// Hardware SPI connection
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
void beginDS1307()
{
// Read the values (date and time) of the DS1307 module
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(clear);
Wire.endTransmission();
Wire.requestFrom(DS1307_ADDRESS, 0x07);
seconds = bcdToDec(Wire.read());
minutes = bcdToDec(Wire.read());
hours = bcdToDec(Wire.read() & 0xff);
wday = bcdToDec(Wire.read());
mday = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
}
uint8_t decToBcd(uint8_t value)
{
return ((value / 10 * 16) + (value % 10));
}
uint8_t bcdToDec(uint8_t value)
{
return ((value / 16 * 10) + (value % 16));
}
// Code for reading clock time
void getTime(char *psz, bool f = true)
{
sprintf(psz, "%02d%c%02d", hours, (f ? ':' : ' '), minutes);
}
// Code for reading clock date
void getDate(char *psz)
{
char szBuf[10];
sprintf(psz, "%d %s %04d", mday, mon2str(month, szBuf, sizeof(szBuf) - 1), (year + 2000));
}
// Get a label from PROGMEM into a char array
char *mon2str(uint8_t mon, char *psz, uint8_t len)
{
static const __FlashStringHelper* str[] =
{
F("Januari"), F("Februari"), F("Maret"), F("April"),
F("Mei"), F("Juni"), F("Juli"), F("Agustus"),
F("September"), F("Oktober"), F("November"), F("Desember")
};
strncpy_P(psz, (const char PROGMEM *)str[mon - 1], len);
psz[len] = '\0';
return (psz);
}
char *dow2str(uint8_t code, char *psz, uint8_t len)
{
static const __FlashStringHelper* str[] =
{
F("Minggu"), F("Senin"), F("Selasa"),
F("Rabu"), F("Kamis"), F("Jumat"),
F("Sabtu")
};
strncpy_P(psz, (const char PROGMEM *)str[code - 1], len);
psz[len] = '\0';
return (psz);
}
void setup(void)
{
Wire.begin();
P.begin(2);
P.setInvert(false);
P.setZone(0, 0, 3); // P.setZone(0, 0, 3);
P.setZone(1, 4, 7); // P.setZone(1, 4, 7);
P.displayZoneText(1, szMesg, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(0, szMesg, PA_CENTER, SPEED_TIME, 0, PA_PRINT, PA_NO_EFFECT);
}
void loop(void)
{
// static uint32_t lastTime = 0; // Memory (ms)
// static uint8_t display = 0; // Current display mode
// static bool flasher = false; // Seconds passing flasher
beginDS1307();
// P.displayAnimate();
switch (mode) {
case 0:
tampilJambesar();
break;
// case 1:
// if (tpl_nama == 1) {
// tampilPesan(1);
// } else {
// mode = 2;
// } // Nama Masjid
// break;
// case 2:
// if (tpl_pesan == 1) {
// tampilPesan(2);
// } else {
// mode = 3;
// } // Pesan
// break;
// case 3:
// if (tpl_hijriyah == 1) {
// tampilPesan(3);
// } else {
// mode = 4;
// } // Tanggal Hijriyah
// break;
// case 4:
// if (tpl_masehi == 1) {
// tampilPesan(4);
// } else {
// mode = 5;
// } // Tanggal Masehi
// break;
// case 5:
// //if( tpl_jws == 1 ){ tampilPesan(5); } else { mode = 6;} // Waktu Sholat
// tampilPesan(5); // Waktu Sholat
// break;
// case 6:
// tampilAdzan();
// break;
// case 7:
// tampilIqomah();
// break;
// case 8:
// if (tpl_matikan == 1) {
// tampilPesan(8);
// } else {
// mode = 9;
// } // Setelah iqomah matikan HP
// break;
// case 9:
// tampilPesan(9);
// break;
}
}
void tampilJambesar() {
// Tampilkan Jam Besar
static uint32_t lastTime = 0; // millis() memory
static bool flasher = false; // seconds passing flasher
P.displayAnimate();
if (P.getZoneStatus(0))
{
P.setPause(1, 3000);
P.setPause(0, 3000);
P.setFont(1, ya_atas);
P.setFont(0, ya_bawah);
if ((millis() - lastTime) >= 1000)
{
lastTime = millis();
getTime(szMesg, flasher);
flasher = !flasher;
P.setTextEffect(1, PA_SCROLL_DOWN, PA_SCROLL_UP);
P.setTextEffect(0, PA_SCROLL_UP, PA_SCROLL_DOWN);
}
P.displayReset(1);
P.displayReset(0);
}
// P.displayZoneText(1, szMesg, PA_CENTER, SPEED_TIME, 5000, PA_SCROLL_DOWN, PA_SCROLL_UP);
// P.displayZoneText(0, szMesg, PA_CENTER, SPEED_TIME, 5000, PA_SCROLL_UP, PA_SCROLL_DOWN);
}