- Arduino UNO
- 1 Panel LED P10
- Bluetooth HC-05 atau HC-06
- RTC DS3231
- Buzzer Active
- Konverter Arduino ke DMD
- Charge HP 5V untuk power JWS
- Kabel Jumper secukupnya
- Kabel USB
- Komputer atau Laptop yang sdh terintal Arduino IDE 1.8.5
- Sumber Listrik
- File Utama
- File Perhitungan Waktu Sholat
- File gambar desai Tampilan
- File Parameter
- File Penamaan ID
- File Tampilan Puasa
//**************************************************************************************/
#include <SPI.h>
#include <DMD3asis.h>
#include <font/KecNumber.h>
#include <font/BigNumber.h>
#include <font/Font4x6.h>
#include <font/SystemFont5x7.h>
#include <font/Font3x5.h>
#include <font/Angka6x7.h>
#include <DS3231.h>
#include <EEPROM.h>
#include <avr/pgmspace.h>
#include <Wire.h>
#include <MemoryFree.h>
#define BUZZ A0
#define Font0 Font4x6
#define Font3 BigNumber
#define Font2 Font3x5
#define Font1 SystemFont5x7
#define Font4 KecNumber
#define Font5 Angka6x7
// Object Declarations
DMD3 Disp(1,1);
char *pasar[] ={"WAGE", "KLIWON", "LEGI", "PAHING", "PON"};
int maxday[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
RTClib RTC;
DS3231 Clock;
//Structure of Variable
typedef struct // loaded to EEPROM
{
uint8_t state; //1 1 byte add 0
float L_LA; //2 4 byte add 1
float L_LO; //3 4 byte add 5
float L_AL; //4 4 byte add 9
float L_TZ; //5 4 byte add 13
uint8_t MT; //6 1 byte add 17 // value 1-masjid 2-mushollah 3-surau 4-langgar
uint8_t BL; //7 1 byte add 18
uint8_t IH; //8 1 byte add 19
uint8_t SO; //9 1 byte add 20
uint8_t JM; //10 1 byte add 21
uint8_t I1; //11 1 byte add 22
uint8_t I4; //12 1 byte add 23
uint8_t I5; //13 1 byte add 24
uint8_t I6; //14 1 byte add 25
uint8_t I7; //15 1 byte add 26
uint8_t BZ; //16 1 byte add 27
uint8_t SI; //17 1 byte add 28
uint8_t ST; //18 1 byte add 29
uint8_t SU; //19 1 byte add 30
int8_t CH; //20 1 byte add 31
} struct_param;
typedef struct
{
uint8_t hD;
uint8_t hM;
uint16_t hY;
} hijir_date;
// Variable by Structure
struct_param Prm;
hijir_date nowH;
// Time Variable
DateTime now;
float floatnow = 0;
uint8_t daynow = 0;
uint8_t ty_puasa = 0;
uint8_t hd_puasa = 0;
int8_t SholatNow = -1;
boolean jumat = false;
boolean azzan = false;
uint8_t reset_x = 0;
//Other Variable
float sholatT[8] = {0,0,0,0,0,0,0,0};
uint8_t Iqomah[8] = {0,0,0,0,0,0,0,0};
//Blue tooth Pram Receive
char CH_Prm[155];
int DWidth = Disp.width();
int DHeight = Disp.height();
boolean DoSwap;
int RunSel = 1; //
int RunFinish = 0 ;
//=======================================
//===SETUP===============================
//=======================================
void setup()
{ //init comunications
Wire.begin();
Serial.begin(9600);
// Get Saved Parameter from EEPROM
updateTime();
GetPrm();
//init P10 Led Disp & Salam
Disp_init();
}
//=======================================
//===MAIN LOOP Function =================
//=======================================
void loop()
{
// Reset & Init Display State
updateTime(); //every time
check_azzan(); //check Sholah Time for Azzan
DoSwap = false ;
fType(1);
Disp.clear();
// Timer Function every 10 Minutes
// Up All function with Timer in this fuction
Timer_Minute(1);
// =========================================
// List of Display Component Block =========
// =========================================
anim_JG(1); // addr: 1 show date time
dwMrq(drawMasjidName(),75,2,2); // addr: 2 show Masjid Name
dwMrq(drawDayDate() ,75,1,3); // addr: 3 show Hijriah date
dwMrq(msgPuasa(hd_puasa,ty_puasa),75,0,4); // addr: 5 show Remander Puasa
drawSholat(5); // addr: 5 show sholat time
dwMrq(drawInfo(130) ,75,1,6); // addr: 6 show Info 1
anim_DT(7); // addr: 7 show date time
dwMrq(drawInfo(280) ,75,2,8); // addr: 8 show Info 2
drawSholat(9); // addr: 9 show sholat time
dwMrq(drawInfo(430) ,75,1,10); // addr: 10 show Info 3
drawAzzan(100); // addr: 100 show Azzan
drawIqomah(101); // addr: 101 show Iqomah
dwMrq(drawInfo(580),50,0,102); //Message Sholat biasa // addr: 202 show Message Sholah
dwMrq(drawInfo(730),50,0,103); //Message Sholat jumat // addr: 203 show Message Jum'at
blinkBlock(104); // addr: 104 show Blink Sholat
// =========================================
// Display Control Block ===================
// =========================================
if(RunFinish==1) {RunSel = 2; RunFinish =0;} //after anim 1 set anim 2
if(RunFinish==2) {RunSel = 3; RunFinish =0;} //after anim 2 set anim 3
if(RunFinish==3) //after anim 3 set anim 5 or anim 4 if puasa
{
if (ty_puasa!=0) {RunSel = 4; RunFinish =0;}
else {RunSel = 5; RunFinish =0;}
}
if(RunFinish==4) {RunSel = 5; RunFinish =0;} //after anim 4 set anim 5
if(RunFinish==5) {RunSel = 6; RunFinish =0;} //after anim 5 set anim 6
if(RunFinish==6) {RunSel = 7; RunFinish =0;} //after anim 6 set anim 7
if(RunFinish==7) {RunSel = 8; RunFinish =0;} //after anim 7 set anim 8
if(RunFinish==8) {RunSel = 9; RunFinish =0;} //after anim 8 set anim 9
if(RunFinish==9) {RunSel = 10; RunFinish =0;} //after anim 9 set anim 10
if(RunFinish==10) {RunSel = 1; RunFinish =0;} //after anim 10 set anim 1
if(RunFinish==100 and jumat ) {RunSel = 103; RunFinish = 0; reset_x = 1;} //after Azzan Jumat (anim 100)
else if(RunFinish==100) {RunSel = 101; RunFinish =0;} //after Azzan Sholah (Iqomah)
if(RunFinish==101) {RunSel = 102; RunFinish =0; reset_x=1;} //after Iqomah(anim 101) set Message Sholah (anim 102)
if(RunFinish==102) {RunSel = 104; RunFinish =0;} //after Message Sholah (anim 102) set Blink Sholah(anim 104)
if(RunFinish==103) {RunSel = 104; RunFinish =0;} //after Messagw Jum'at (anim 103) set Blink Sholah(anim 104)
if(RunFinish==104) {RunSel = 1; RunFinish =0;} //after Blink Sholah back to anim 1
// =========================================
// Swap Display if Change===================
// =========================================
if(DoSwap){Disp.swapBuffers();} // Swap Buffer if Change
}
// =========================================
// DMD3 P10 utility Function================
// =========================================
void Disp_init()
{ Disp.setDoubleBuffer(true);
Timer1.initialize(2000);
Timer1.attachInterrupt(scan);
setBrightness(int(Prm.BL));
fType(1);
Disp.clear();
Disp.swapBuffers();
}
void setBrightness(int bright)
{ Timer1.pwm(9,bright);}
void scan()
{ Disp.refresh();}
// =========================================
// Time Calculation Block===================
// =========================================
void updateTime()
{ now = RTC.now();
floatnow = (float)now.hour() + (float)now.minute()/60 + (float)now.second()/3600;
daynow = Clock.getDoW(); // load day Number
}
void Timer_Minute(int repeat_time) //load every 1 minute
{
static uint16_t lsRn;
uint16_t Tmr = millis();
if((Tmr-lsRn)>(repeat_time*60000))
{
lsRn =Tmr;
update_All_data();
Serial.print("freeMemory()=");Serial.println(freeMemory());
SendPrm();
}
}
void update_All_data()
{
uint8_t date_cor = 0;
updateTime();
sholatCal(); // load Sholah Time
check_puasa(); // check jadwal Puasa Besok
if(floatnow>sholatT[6]) {date_cor = 1;} // load Hijr Date + corection next day after Mhagrib
nowH = toHijri(now.year(),now.month(),now.day(),date_cor); // load Hijir Date
if ((floatnow > (float)21) or (floatnow < (float)3.5) ) {setBrightness(15);}
else {setBrightness(Prm.BL);}
}
void check_azzan()
{ //Check Waktu Sholat
SholatNow = -1;
for(int i=0; i <=7; i++)
{
if (i!=0 and i!=2 and i!=3) // bukan terbit dan bukan dhuha
{
if(floatnow >= sholatT[i])
{
SholatNow = i;
if(!azzan and (floatnow > sholatT[i]) and (floatnow < (sholatT[i]+0.03)))
{
if(daynow ==6 and SholatNow ==4 and Prm.MT==1) {jumat=true;}
azzan =true;
RunSel = 100;
}
}
}
}
}
//------------------------------------------
// Function calculate Pray Time
//------------------------------------------
/*Macro Function */
#define d2r(x) x*M_PI/180
#define r2d(x) x*180/M_PI
//Constanta
const float lunarY = 354.367068f;
// Main Function
void sholatCal()
{
float EJD = E_Julian_date(now.year(),now.month(),now.day(),Prm.L_LO);
float Decl=Dql(EJD);
float EqOfTime=EqT(EJD);
Pray_Time(Prm.L_TZ, Prm.L_LA, Prm.L_LO,Prm.L_AL,Decl, EqOfTime );
}
//Julian Date at GMT mid day
float E_Julian_date(int Year,int Month,int Days,float Longitude) // juliant date - 2451545
{
if (Month <= 2)
{
Year -= 1;
Month += 12;
}
float A = floor(((float)Year/100.0));
float B = 2 - A + floor(A/4.0);
float CLong = Longitude/(float)(15 * 24);
float JD = floor(365.25 *(float)(Year+ 4716))
- 2451545
+ floor(30.6001 * (float)(Month + 1))
+ (float)Days + B
- 1524.5
-CLong;
return JD;
}
//Sun Declination
float EqT(const float EJD)
{
float g = fix_angle(357.529f + 0.98560028f* EJD);
float q = fix_angle(280.459f + 0.98564736f* EJD);
float L = fix_angle(q + 1.915* sin(d2r(g)) + 0.020* sin(d2r(2*g)));
float e = (23.439f - 0.00000036f* EJD);
float RA = r2d(atan2(cos(d2r(e))* sin(d2r(L)), cos(d2r(L))))/ 15;
float Eq =(q/15-fix_hour(RA));
return Eq;
// Ds = r2d(asin(sin(d2r(e))* sin(d2r(L)))); // declination of the Sun
}
float Dql(float EJD)
{
float g = fix_angle((357.529f + 0.98560028f* EJD));
float q = fix_angle((280.459f + 0.98564736f* EJD));
float L = fix_angle((q + 1.915f* sin(d2r(g)) + 0.020f* sin(d2r(2*g))));
float e = (23.439f - 0.00000036f* EJD);
float dd = r2d(asin(sin(d2r(e))* sin(d2r(L)))); // declination of the Sun
return dd;
}
float HourAngle( float Alfa, float Declination, float Latitude)
{
float rn =acos(
(-sin(d2r(Alfa))-sin(d2r(Latitude))*sin(d2r(Declination)))
/
(cos(d2r(Latitude))*cos(d2r(Declination)))
)/15;
return r2d(rn);
}
void Pray_Time(float TimeZone, float Latitude, float Longitude,float Altitude,float Declination, float EquationOfTime )
{
// Dzuhur
float BaseTime = fix_hour((float)12+TimeZone-(Longitude/15)-EquationOfTime);
sholatT[4] = BaseTime + (float)Prm.IH/60;
// Ashr
float alfa =r2d(-atan(1 / (1+tan(d2r(fabs(Latitude-Declination))))));
float HA = HourAngle(alfa,Declination,Latitude);
sholatT[5] = BaseTime + HA + (float)Prm.IH/60;
// Maghrib
alfa = 0.8333f+0.0347f*sqrt(Altitude);
HA = HourAngle(alfa,Declination,Latitude);
sholatT[6] = BaseTime + HA + (float)Prm.IH/60;
// Terbit
sholatT[2] = BaseTime - HA;
// Isya
HA = HourAngle((float)18,Declination,Latitude);
sholatT[7] = BaseTime + HA + (float)Prm.IH/60;
// Shubuh
HA = HourAngle((float)20,Declination,Latitude);
sholatT[1] = BaseTime - HA + (float)Prm.IH/60;
// Imsak
sholatT[0] = sholatT[1]-(float)10/60;
// Dhuha
HA = HourAngle((float)-4.5,Declination,Latitude);
sholatT[3] = BaseTime - HA;
char buff[100];
}
float fix_hour(float a)
{
a = a - (float)24.0 * floor(a / 24.0);
a = a < 0.0 ? a + 24.0 : a;
return a;
}
float fix_angle(float a)
{
a = a - (float)360.0 * floor(a / 360.0);
a = a < 0.0 ? a + 360.0 : a;
return a;
}
//------------------------------------------
// Function calculate Hijriah Date
//------------------------------------------
long Days(uint16_t Y,uint8_t M,uint8_t D)
{
if (M < 3)
{
Y -= 1;
M +=12;
}
Y = Y - 2000;
long ndays= floor(365.25*Y)+floor(30.6001*(M + 1))+floor(Y/100)+floor(Y/400)+D+196;
//long ndays= d1 + d2 - A + B + D + 196;
return ndays;
}
long DaysHijri(uint16_t Y,uint8_t M,uint8_t D)
{
Y = Y - 1420;
long hari = floor(29.5*M - 28.999)+floor(lunarY*Y)+D ;
return hari;
}
hijir_date toHijri(uint16_t Y, uint8_t M, uint8_t D,uint8_t cor) // core --> corection date today=0 yesterday=-1 tomorrow=1
{
hijir_date BuffDate;
long nday = Days(Y, M, D)+ Prm.CH + cor;
long tahun = floor(nday/lunarY) + 1420;
long bulan = 1;
long harike = 1;
while(DaysHijri(tahun, bulan, 1) <= nday){tahun++;};
tahun--;
while(DaysHijri(tahun, bulan, 1) <= nday){bulan++;};
bulan--;
harike = 1 + nday - DaysHijri(tahun, bulan, 1);
if (bulan == 13){bulan = 12; harike += 29;};
BuffDate.hD = harike;
BuffDate.hM = bulan;
BuffDate.hY = tahun;
return BuffDate;
}
File gambar desai Tampilan :// =========================================
// Drawing Content Block====================
// =========================================
void drawAzzan(int DrawAdd)
{
// check RunSelector
if(!dwDo(DrawAdd)) return;
uint8_t ct_limit =40; //harus angka genap
static uint8_t ct;
static uint16_t lsRn;
uint16_t Tmr = millis();
if((Tmr-lsRn) > 500 and ct <= ct_limit)
{
lsRn = Tmr;
if((ct%2) == 0)
{ //Disp.drawRect(1,2,62,13);
fType(0);
dwCtr(0,0,"ADZAN");
fType(1);
if(jumat) {dwCtr(0,8,sholatN(8));}
else {dwCtr(0,8,sholatN(SholatNow));}
Buzzer(1);
}
else
{ Buzzer(0);}
DoSwap = true;
ct++;
}
if ((Tmr-lsRn)>2000 and (ct > ct_limit))
{dwDone(DrawAdd);
ct = 0;
Buzzer(0);}
}
void drawIqomah(int DrawAdd) // Countdown Iqomah (9 menit)
{
// check RunSelector
if(!dwDo(DrawAdd)) return;
static uint16_t lsRn;
uint16_t Tmr = millis();
static int ct;
int mnt, scd,cn_l ;
char locBuff[6];
cn_l = (Iqomah[SholatNow]*60);
//Disp.drawRect(1,2,62,13);
if((Tmr-lsRn) > 1000 and ct <=cn_l)
{
lsRn = Tmr;
mnt = floor((cn_l-ct)/60);
scd = (cn_l-ct)%60;
if(mnt>0) {sprintf(locBuff,"%02d:%02d",mnt,scd);}
else {sprintf(locBuff,"%02d",scd);}
if((ct%2) == 0){
fType(0);
dwCtr(0,-1,"IQOMAH");}
fType(0);
dwCtr(0,8,locBuff);
if (ct> (cn_l-10)) Buzzer(1); // Buzzer on 2 seccon before Iqomah
ct++;
DoSwap = true;
}
if (ct > cn_l)
{
dwDone(DrawAdd);
ct = 0;
Buzzer(0);
}
}
void drawSholat_S(int sNum,int c) // Box Sholah Time
{
char BuffTime[10];
char BuffShol[7];
float stime = sholatT[sNum];
uint8_t shour = floor(stime);
uint8_t sminute = floor((stime-(float)shour)*60);
uint8_t ssecond = floor((stime-(float)shour-(float)sminute/60)*3600);
sprintf(BuffTime,"%02d:%02d",shour,sminute);
// Disp.drawRect(c+1,2,62,13);
fType(1); dwCtr(c,0,sholatN(sNum));
fType(0); dwCtr(c,9,BuffTime);
DoSwap = true;
}
void drawSholat(int DrawAdd)
{
// check RunSelector
// int DrawAdd = 0b0000000000000100;
if(!dwDo(DrawAdd)) return;
static uint8_t x;
static uint8_t s; // 0=in, 1=out
static uint8_t sNum;
static uint16_t lsRn;
uint16_t Tmr = millis();
uint8_t c=0;
uint8_t first_sNum = 0;
int DrawWd=DWidth - c;
if((Tmr-lsRn)>10)
{
if(s==0 and x<(DrawWd/2)){x++;lsRn=Tmr;}
if(s==1 and x>0){x--;lsRn=Tmr;}
}
if((Tmr-lsRn)>2000 and x ==(DrawWd/2)) {s=1;}
if (x == 0 and s==1)
{
if (sNum <7 0="" 1="" 2="" 3="" 7="" and="" buff="" buffh="" buffm="" c="" char="" d="" date="" disp.drawfilledrect="" disp.drawtext="" doswap="true;" drawgreg_ds="" drawsholat_s="" drawsmallts="" dwctr="" dwdone="" else="" first_snum="" ftype="" if="" int="" isp.drawline="" lsrn="" mr-lsrn="" now.day="" now.hour="" now.minute="" now.month="" now.year="" or="" raw="" rawadd="" rawwd="" rm.si="=0" rm.st="=0" rm.su="=0" s="=" snum="" sprintf="" static="" tmr="millis();" uff="" uffh="" uffm="" uint16_t="" void="" x-10="" x="" y-2="" y="">1000) lsRn = Tmr;
DoSwap = true;
}
void drawGreg_TS(uint16_t y) // Draw Time
{
char Buff[20];
//sprintf(Buff,"%02d:%02d:%02d",now.hour(),now.minute(),now.second());
sprintf(Buff,"%02d:%02d",now.hour(),now.minute());
dwCtr(0,y,Buff);
DoSwap = true;
}
void drawGreg_cil(uint16_t y) // Draw Time
{
char Buff[20];
sprintf(Buff,"%02d:%02d:%02d",now.hour(),now.minute(),now.second());
dwCtr(0,y,Buff);
DoSwap = true;
}
void Jam_GD(uint16_t y) // Draw Time Depan
{
char BuffJ[6];
char BuffM[6];
char BuffD[6];
sprintf(BuffJ,"%02d",now.hour());
sprintf(BuffM,"%02d",now.minute());
sprintf(BuffD,"%02d",now.second());
fType(5);
Disp.drawText(0,y,BuffJ);
Disp.drawText(0,y+8,BuffM);
fType(3);
Disp.drawText(19,y,BuffD);
Disp.drawRect(15,y+3,16,y+5,1);
Disp.drawRect(15,y+10,16,y+12,1);
DoSwap = true;
}
void anim_DT(int DrawAdd)
{
// check RunSelector
if(!dwDo(DrawAdd)) return;
static uint8_t y;
static uint8_t s; // 0=in, 1=out
static uint16_t lsRn;
uint16_t Tmr = millis();
if((Tmr-lsRn)>100)
{
if(s==0 and y<17 and="" if="" lsrn="Tmr;y++;}" s="=1" y="">0){lsRn=Tmr;y--;}
}
if((Tmr-lsRn)>10000 and y ==17) {s=1;}
if (y==7)
{
// Disp.drawRect(1,2,62,13);
}
if (y == 0 and s==1) {dwDone(DrawAdd); s=0;}
fType(4);
drawGreg_cil(y-16);
// fType(2);
//drawGreg_DS(16-y);
}
void anim_JG(int DrawAdd)
{
// check RunSelector
if(!dwDo(DrawAdd)) return;
static uint8_t y;
static uint8_t s; // 0=in, 1=out
static uint16_t lsRn;
uint16_t Tmr = millis();
if((Tmr-lsRn)>100)
{
if(s==0 and y<17 and="" if="" lsrn="Tmr;y++;}" s="=1" y="">0){lsRn=Tmr;y--;}
}
if((Tmr-lsRn)>10000 and y ==17) {s=1;}
if (y==7)
{
// Disp.drawRect(1,2,62,13);
}
if (y == 0 and s==1) {dwDone(DrawAdd); s=0;}
//fType(1);
//drawGreg_TS(y-8);
Jam_GD(17-y);
}
void dwMrq(const char* msg, int Speed, int dDT, int DrawAdd)
{
// check RunSelector
static uint16_t x;
if(!dwDo(DrawAdd)) return;
if (reset_x !=0) { x=0;reset_x = 0;}
static uint16_t lsRn;
int fullScroll = Disp.textWidth(msg) + DWidth;
uint16_t Tmr = millis();
if((Tmr-lsRn)> Speed)
{ lsRn=Tmr;
if (x < fullScroll) {++x;}
else { dwDone(DrawAdd);
x = 0;return;}
if(dDT==1)
{
fType(1); //Marquee
Disp.drawText(DWidth - x, 0, msg);
fType(0);
if (x<=6) { drawGreg_TS(16-x);}
else if (x>=(fullScroll-6)) { drawGreg_TS(16-(fullScroll-x));}
else { Disp.drawRect(1,8,30,8);
drawGreg_TS(9);}
}
else if(dDT==2)
{
fType(0);
if (x<=6) { drawGreg_TS(x-6);}
else if (x>=(fullScroll-6)) { drawGreg_TS((fullScroll-x)-6);}
else { Disp.drawRect(1,7,30,7);
drawGreg_TS(-1);}
fType(1); //Marquee
Disp.drawText(DWidth - x, 9 , msg);
}
else
{
fType(1);
Disp.drawLine(1,2,62,2);
Disp.drawLine(1,13,62,13);
Disp.drawText(DWidth - x, 4, msg);
}
DoSwap = true;
}
}
void blinkBlock(int DrawAdd)
{
// check RunSelector
if(!dwDo(DrawAdd)) return;
static uint16_t lsRn;
static uint16_t ct, ct_l;
uint16_t Tmr = millis();
int mnt, scd;//
char locBuff[6];//
if(jumat) {ct_l = Prm.JM * 60;}
else {ct_l = Prm.SO * 60;}
jumat =false;
if((Tmr-lsRn)> 1000)
{ lsRn=Tmr;
//Disp.drawChar(1, 1 , ct);
mnt = floor((ct_l-ct)/60);
scd = (ct_l-ct)%60;
sprintf(locBuff,"%d:%02d",mnt,scd);
fType(2);
Disp.drawText(1,7,locBuff); // tampil tunggu sholat
if((ct%2) == 0)
{
Disp.drawFilledRect(DWidth-3, DHeight-3, DWidth-2, DHeight-2);}
DoSwap = true;
ct++;}
if (ct> ct_l)
{ dwDone(DrawAdd);
azzan = false;
ct = 0;
}
// Disp.drawText(1,7,String(ct_l-ct));
}
// =========================================
// Drawing Tools============================
// =========================================
boolean dwDo(int DrawAdd)
{ if (RunSel== DrawAdd) {return true;}
else return false;}
void dwDone(int DrawAdd)
{ RunFinish = DrawAdd;
RunSel = 0;}
void dwCtr(int x, int y,const char* Msg)
{ int tw = Disp.textWidth(Msg);
int th = Disp.textHeight();
int c = int((DWidth-x-tw)/2);
Disp.drawFilledRect(x+c-1,y,x+tw+c,y+th,0);
Disp.drawText(x+c,y,Msg);}
void Buzzer(uint8_t state)
{
if(state ==1 and Prm.BZ == 1)
{tone(BUZZ, 500, 400);}
else
{noTone(BUZZ);}
}
void fType(int x)
{
if(x==0) Disp.setFont(Font0);
else if(x==1) Disp.setFont(Font1);
else if(x==2) Disp.setFont(Font2);
else if(x==3) Disp.setFont(Font3);
else if(x==4) Disp.setFont(Font4);
else Disp.setFont(Font5);
}
// digunakan untuk menghitung hari pasaran
int jumlahhari(){
DateTime now = RTC.now();
int d= now.day();
int m= now.month();
int y= now.year();
int hb[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365};
int ht = (y - 1970) * 365 - 1;
int hs = hb[m - 1] + d;
int kab = 0;
int i;
if(y % 4 == 0) {
if(m > 2) {
hs++;
}
}
for(i = 1970; i < y; i++) {
if(i % 4 == 0) {
kab++;
}
}
return (ht + hs + kab);
}
17>17>7>
File Parameter :
void serialEvent()
{
int prm_idx = 0;
char bchar;
bchar =Serial.peek();
if ((bchar == 'C') or (bchar == 'N') or (bchar == 'S'))
{
while ((bchar != '\n')and(prm_idx < 150))
{
if(Serial.available())
{
bchar = (char)Serial.read();
CH_Prm[prm_idx]=bchar;
prm_idx ++;
Buzzer(1);
}
}
CH_Prm[prm_idx-1]='\0';
LoadPrm();
}
else
{
while(Serial.available()) {Serial.read();}
}
}
void LoadPrm()
{
String BT_Param;
uint16_t eeAdd = 0;
uint8_t eePut = 0;
uint8_t eeMax = 0;
uint8_t lenprm = strlen(CH_Prm)-3;
// Put Char Data
if (CH_Prm[0]=='C')
{ if(CH_Prm[1]=='M' and CH_Prm[2]=='N') {eeAdd = 58; eeMax=24;}
else if(CH_Prm[1]=='M' and CH_Prm[2]=='A') {eeAdd = 85; eeMax=44;}
else if(CH_Prm[1]=='N' and CH_Prm[2]=='1') {eeAdd = 130; eeMax=149;}
else if(CH_Prm[1]=='N' and CH_Prm[2]=='2') {eeAdd = 280; eeMax=149;}
else if(CH_Prm[1]=='N' and CH_Prm[2]=='3') {eeAdd = 430; eeMax=149;}
else if(CH_Prm[1]=='S' and CH_Prm[2]=='M') {eeAdd = 580; eeMax=149;}
else if(CH_Prm[1]=='J' and CH_Prm[2]=='M') {eeAdd = 730; eeMax=149;}
int eeCount =0;
while((eeCount<= lenprm) and (eeCount < eeMax))
{
EEPROM.update(eeAdd+eeCount,CH_Prm[3+eeCount]);
eeCount++;
}
EEPROM.update(eeAdd+eeCount,'\0');
}
// Put Numeric Data
else if (CH_Prm[0] =='N')
{
BT_Param = String(CH_Prm);
if(BT_Param.substring(1,3).equals("LA")) {eeAdd = 1 ; eePut=1;}
else if(BT_Param.substring(1,3).equals("LO")) {eeAdd = 5 ; eePut=1;}
else if(BT_Param.substring(1,3).equals("AL")) {eeAdd = 9 ; eePut=1;}
else if(BT_Param.substring(1,3).equals("TZ")) {eeAdd = 13; eePut=1;}
else if(BT_Param.substring(1,3).equals("MT")) {eeAdd = 17; eePut=2;}
else if(BT_Param.substring(1,3).equals("BL")) {eeAdd = 18; eePut=2;}
else if(BT_Param.substring(1,3).equals("IH")) {eeAdd = 19; eePut=2;}
else if(BT_Param.substring(1,3).equals("SO")) {eeAdd = 20; eePut=2;}
else if(BT_Param.substring(1,3).equals("JM")) {eeAdd = 21; eePut=2;}
else if(BT_Param.substring(1,3).equals("I1")) {eeAdd = 22; eePut=2;}
else if(BT_Param.substring(1,3).equals("I4")) {eeAdd = 23; eePut=2;}
else if(BT_Param.substring(1,3).equals("I5")) {eeAdd = 24; eePut=2;}
else if(BT_Param.substring(1,3).equals("I6")) {eeAdd = 25; eePut=2;}
else if(BT_Param.substring(1,3).equals("I7")) {eeAdd = 26; eePut=2;}
else if(BT_Param.substring(1,3).equals("BZ")) {eeAdd = 27; eePut=2;}
else if(BT_Param.substring(1,3).equals("SI")) {eeAdd = 28; eePut=2;}
else if(BT_Param.substring(1,3).equals("ST")) {eeAdd = 29; eePut=2;}
else if(BT_Param.substring(1,3).equals("SU")) {eeAdd = 30; eePut=2;}
else if(BT_Param.substring(1,3).equals("CH")) {eeAdd = 31; eePut=3;} //update
if(eePut == 1)
{
EEPROM.put(eeAdd,BT_Param.substring(3,BT_Param.length()).toFloat());
}
if(eePut == 2)
{
EEPROM.put(eeAdd,(uint8_t)BT_Param.substring(3,BT_Param.length()).toInt());
}
if(eePut == 3) // put uint8_t
{
EEPROM.put(eeAdd,(int8_t)BT_Param.substring(3,BT_Param.length()).toInt());
}
}
else
if (CH_Prm[0]=='S' and CH_Prm[1]=='D' and CH_Prm[2]=='T')
{
BT_Param = String(CH_Prm);
Clock.setClockMode(false);
Clock.setDate(byte(BT_Param.substring(3,5).toInt()));
Clock.setMonth(byte(BT_Param.substring(5,7).toInt()));
Clock.setYear(byte(BT_Param.substring(7,9).toInt()));
Clock.setHour(byte(BT_Param.substring(9,11).toInt()));
Clock.setMinute(byte(BT_Param.substring(11,13).toInt()));
Clock.setSecond(byte(BT_Param.substring(13,15).toInt()));
Clock.setDoW(byte(BT_Param.substring(15,16).toInt()));
}
// Get New/updeted parameter*/
GetPrm();
}
void GetPrm()
{
// Serial.println("Get parameter");
// Get Parameter and check
EEPROM.get(0, Prm);
if(Prm.state != 212) //check value of Prm State .. set Default
{
set_default_prm();
}
if (now.year() < 2018)//check date time .. less than 1 jan 2018 set Default
{
set_default_time();
}
Iqomah[1]=Prm.I1;
Iqomah[4]=Prm.I4;
Iqomah[5]=Prm.I5;
Iqomah[6]=Prm.I6;
Iqomah[7]=Prm.I7;
// user New Parameter
setBrightness(int(Prm.BL));
update_All_data();
// SendPrm();
}
void set_default_prm()
{
// Put Parameter start form addr 500
Prm = (struct_param){212,-6.39524,106.80256,45,7,1,20,2,10,30,15,10,10,7,10,1,1,1,1,0};
EEPROM.put(0,Prm);
EEPROM.put(58, "Mujahid 212\0");
EEPROM.put(85, "Sragen\0");
EEPROM.put(130,"Info 1\0");
EEPROM.put(280,"Info 2\0");
EEPROM.put(430,"Info 3\0");
EEPROM.put(580,"Lurus dan rapatkan Shaf sebelum Sholat ...\0");
EEPROM.put(730,"Harap Tenang dan Matikan HP Anda\0");
}
void set_default_time()
{
Clock.setClockMode(false); // set to 24h
Clock.setYear(byte(18));
Clock.setMonth(byte(1));
Clock.setDate(byte(1));
Clock.setDoW(byte(2));
Clock.setHour(byte(12));
Clock.setMinute(byte(0));
Clock.setSecond(byte(0));
Clock.turnOffAlarm(1);
Clock.turnOffAlarm(2);
}
// for debug
void SendPrm()
{
// char Info1[150];
Serial.print(F("NLA : ")); Serial.print(Prm.L_LA,7);Serial.print("\t");
Serial.print(F("NLO : ")); Serial.print(Prm.L_LO,7);Serial.print("\n");
Serial.print(F("NAL : ")); Serial.print(Prm.L_AL,7);Serial.print("\t");
Serial.print(F("NTZ : ")); Serial.print(Prm.L_TZ,0);Serial.print("\n");
Serial.print(F("NMT : ")); Serial.print(Prm.MT);Serial.print("\t");
Serial.print(F("NIH : ")); Serial.print(Prm.IH);Serial.print("\t");
Serial.print(F("NCH : ")); Serial.print(Prm.CH);Serial.print("\n");
Serial.print(F("NSO : ")); Serial.print(Prm.SO);Serial.print("\t");
Serial.print(F("NJM : ")); Serial.print(Prm.JM);Serial.print("\n");
Serial.print(F("NI1 : ")); Serial.print(Prm.I1);Serial.print("\t");
Serial.print(F("NI4 : ")); Serial.print(Prm.I4);Serial.print("\t");
Serial.print(F("NI5 : ")); Serial.print(Prm.I5);Serial.print("\n");
Serial.print(F("NI6 : ")); Serial.print(Prm.I6);Serial.print("\t");
Serial.print(F("NI7 : ")); Serial.print(Prm.I7);Serial.print("\t");
Serial.print(F("NBZ : ")); Serial.print(Prm.BZ);Serial.print("\n");
Serial.print(F("NSI : ")); Serial.print(Prm.SI);Serial.print("\t");
Serial.print(F("NST : ")); Serial.print(Prm.ST);Serial.print("\t");
Serial.print(F("NSU : ")); Serial.print(Prm.SU);Serial.print("\n");
Serial.print(F("NBL : ")); Serial.print(Prm.BL);Serial.print("\n");
for(int i =0; i <=7;i++){
Serial.print("iqomah"); Serial.print(i); Serial.print("\t"); Serial.println(Iqomah[i]);
}
}
File Penamaan ID :
/*=============================================
* PROGMEM DATA
==============================================*/
// sholatN 9 x 8
const char static sholatN_E[] PROGMEM = { "IMSAK\0\0\0"
"SUBUH\0\0\0"
"TERBT\0\0\0"
"DHUHA\0\0\0"
"DUHUR\0\0\0"
"ASHAR\0\0\0"
"MAGRB\0\0\0"
"ISYA\0\0\0\0"
"JUMAT\0\0\0"
};
//h_month 12 x 11
const char static h_month_E[] PROGMEM = { "MUHARRAM\0\0\0"
"SHAFAR\0\0\0\0\0"
"RAB.AWAL\0\0\0"
"RAB.AKHIR\0\0"
"JUM.AWAL\0\0\0"
"JUM.AKHIR\0\0"
"RAJAB\0\0\0\0\0\0"
"SYA'BAN\0\0\0\0"
"RAMADHAN\0\0\0"
"SYAWAL\0\0\0\0\0"
"DZULQA'DAH\0"
"DZULHIJAH\0\0"};
//m_month 12 x 10
const char static m_month_E[] PROGMEM = { "JAN\0"
"FEB\0"
"MAR\0"
"APR\0"
"MEI\0"
"JUN\0"
"JUL\0"
"AGS\0"
"SEP\0"
"OKT\0"
"NOV\0"
"DES\0"};
//DayName 7 x 7
const char static DayName_E[] PROGMEM = { "AHAD\0\0\0"
"SENIN\0\0"
"SELASA\0"
"RABU\0\0\0"
"KAMIS\0\0"
"JUM'AT\0"
"SABTU\0\0"};
//MT_Name 4 x 10
const char static MT_Name_E[] PROGMEM = { "MASJID\0\0\0\0"
"MUSHOLLA\0\0"
"SURAU\0\0\0\0\0"
"LANGGAR\0\0\0"};
const char static HD_Puasa[] PROGMEM = {
"MARI PUASA\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"
"SUDAHKAH KITA PUASA\0\0\0\0\0\0\0"
"MARI KITA PERBANYAK PUASA\0"
"SELAMAT MENJALANKAN PUASA\0"
};
const char static TY_Puasa[] PROGMEM = {
"SYAWAL\0\0\0\0\0\0\0"
"SYA'BAN\0\0\0\0\0\0"
"SENIN\0\0\0\0\0\0\0\0"
"KAMIS\0\0\0\0\0\0\0\0"
"TENGAH BULAN\0"
"AROFAH\0\0\0\0\0\0\0"
"DZULHIJAH\0\0\0\0"
"TASU'A\0\0\0\0\0\0\0"
"ASYURA\0\0\0\0\0\0\0"
"RAMADHAN\0\0\0\0\0"
};
/*=============================================
// List fungsi Call Name off :
// 1. Header Puasa : Header_Puasa(1-4)
// 2. Sholat Name : sholahN(integer 0-6) 0-Subuh 1-Terbit 2-Dhuha 3-Dzuhur 4-Ashar 5-Magrib 3-Isya
// 3. DayName : DayName(1-7) 1-Minggu .... 7-Sabtu
// 4. Hijriah Month Name : drawGregDate(OutPut String)
// 5. Masehi Month Name : drawHijrDate(OutPut String)
// 6. Masjid Name : drawMasjidName(OutPut String) depend on Masjid Tipe 1-Masjid 2-Musholla 3-Surau 4-Langgar
==============================================*/
char* msgPuasa(int hd, int ty) // get sholat name from EEPROM
{
static char output[50];
char hdBuff[26];
int locLen = (hd-1)*26;
memccpy_P(hdBuff,HD_Puasa+locLen ,0,26);
char tyBuff[13];
locLen = (ty-1)*13;
memccpy_P(tyBuff,TY_Puasa+locLen ,0,13);
if(hd ==1)
{sprintf(output,"%s %s esok hari" ,hdBuff,tyBuff);}
else
{sprintf(output,"%s %s" ,hdBuff,tyBuff);}
return output;
}
char* sholatN(int number) // get sholat name from EEPROM
{
static char locBuff[8];
int locLen = number*8;
memccpy_P(locBuff,sholatN_E+locLen ,0,8);
return locBuff;
}
char * DayName(int number) // get Day Name from EEPROM
{
static char locBuff[7];
int locLen = (number-1)*7;
memccpy_P(locBuff,DayName_E+locLen ,0,7);
return locBuff;
}
char * MonthName(int number) // get Month Name from EEPROM
{
static char locBuff[4];
int locLen = (number-1)*4;
memccpy_P(locBuff,m_month_E+locLen,0,4);
return locBuff;
}
char * drawDayDate()
{
char locBuff[20];
static char out[45];
int locLen = (nowH.hM-1)*11;
memccpy_P(locBuff,h_month_E+locLen,0,11);
sprintf(out,"%s %s,%02d-%02d-%04d %02d %s %dH\0",DayName(daynow),pasar[jumlahhari()%5],now.day(),now.month(),now.year(),nowH.hD,locBuff,nowH.hY);
return out;
}
char * drawMasjidName()
{
char bufMN[75];
static char out[85];
char locBuff[10];
int locLen = (Prm.MT-1)*10;
memccpy_P(locBuff,MT_Name_E+locLen ,0,10);
EEPROM.get(55,bufMN);
sprintf(out,"%s %s\0",locBuff,bufMN);
return out;
}
char * drawInfo(int addr)
{
static char out[150];
EEPROM.get(addr,out);
return out;
}
File Tampilan Puasa :











