Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Bel

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 21

#include <SPI.

h>
#include <DMD3asis.h>
#include <font/Angka6x16.h>
#include <font/Droid_Sans_12.h>
#include <font/huruf6x7.h>
#include <font/Mono5x7.h>

#include <avr/pgmspace.h>
#include <DS3231.h>
#include <Wire.h>

#define fontAbesar Angka6x16


#define fontHbesar Droid_Sans_12
#define fontUmum huruf6x7
#define fontHkecil Mono5x7

DMD3 Disp(1, 1);


RTClib RTC;
DS3231 Clock;

float LA = -6.943;
float LO = 113.573;
int AL = 0;
int TZ = 7;
int BL = 100;

typedef struct {
uint8_t hD;
uint8_t hM;
uint16_t hY;
} hijir_date;

hijir_date nowH;
DateTime now;

int8_t SholatNow = -1;


int8_t KegNow = 0;
boolean azzan = false;
uint8_t reset_x = 0;

float ShT[8] = {0, 0, 0, 0, 0, 0, 0, 0};


int I1=2, I4=2, I5=2, I6=2, I7=2;
int CH = 1;
float tKeg[11] = {0,0,0,0,0,0,0,0,0,0,0};
boolean DoSwap;
int RunS = 1;
int RunF = 0;

bool hAktif = false;


bool formal = false;
bool klokal = false;
bool ekskul = false;
bool kamjum = false;

const int pinBel = A0;


unsigned long prevMillisBel = 0;
int blinkCount = 0;
int blinkTarget = 0;
unsigned long onDuration = 0;
unsigned long offDuration = 0;
bool isBlinking = false;
bool belState = HIGH;
bool startbel = false;

const int pinLamp1 = A1;


const int pinLamp2 = A2;
const int pinLamp3 = A3;

void setup() {
Wire.begin();
Serial.begin(9600);
now = RTC.now();
update_All_data();
Disp_init();
pinMode (pinBel, OUTPUT);
pinMode (pinLamp1, OUTPUT);
pinMode (pinLamp2, OUTPUT);
pinMode (pinLamp3, OUTPUT);
digitalWrite(pinBel, HIGH);
digitalWrite(pinLamp1, HIGH);
digitalWrite(pinLamp2, HIGH);
digitalWrite(pinLamp3, HIGH);
}

void loop() {
now = RTC.now();
update_All_data();
SerCom();
DoSwap = false;
Disp.clear();
AnimSquence();
}

void Disp_init() {
Disp.setDoubleBuffer(true);
Timer1.initialize(2000);
Timer1.attachInterrupt(scan);
Timer1.pwm(9, BL);
Disp.clear();
Disp.swapBuffers();
}

void scan() {
Disp.refresh();
}

void update_All_data() {
sholatCal();
hijryCal();
check_azzan();
cekaktif();
jadwalbel();
kegiatan();
cekLamp();
}

void cekLamp() {
if ((jamnow() >= ShT[6] - (float) 10/60) || (jamnow() < ShT[2] - (float) 30/60))
{
digitalWrite(pinLamp1, LOW);
}
else {
digitalWrite(pinLamp1, HIGH);
}
}

void SerCom() {
if (Serial.available()) {
String input = Serial.readStringUntil('\n');
input.trim();
if (input.startsWith("NTG")) {
Clock.setDate(input.substring(3).toInt());
} else if (input.startsWith("NBL")) {
Clock.setMonth(input.substring(3).toInt());
} else if (input.startsWith("NTH")) {
Clock.setYear(input.substring(3).toInt());
} else if (input.startsWith("NJM")) {
Clock.setHour(input.substring(3).toInt());
} else if (input.startsWith("NMT")) {
Clock.setMinute(input.substring(3).toInt());
} else if (input.startsWith("NDT")) {
Clock.setSecond(input.substring(3).toInt());
} else if (input.startsWith("NHR")) {
Clock.setDoW(input.substring(3).toInt());
} else {
Serial.println("ID tidak dikenal");
}
}
}

int daynow() {
int d = Clock.getDoW();
return d;
}
float jamnow() {
float T = (float) now.hour() + (float) now.minute() / 60.0 + (float)
now.second() / 3600.0;
return T;
}

float jadnow(int j, int m) {


float T = (float) j + (float) m / 60.0;
return T;
}

#define d2r(x) x * M_PI / 180


#define r2d(x) x * 180 / M_PI

const float lunarY = 354.367068f;

void sholatCal() {
float EJD = E_Julian_date(now.year(), now.month(), now.day(), LO);
float Decl = Dql(EJD);
float EqOfTime = EqT(EJD);
Pray_Time(TZ, LA, LO, AL, Decl, EqOfTime);
}
float E_Julian_date(int Year, int Month, int Days, float Longitude) {
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;
}

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;
}

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))));
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) {
float BaseTime = fix_hour((float)12 + TimeZone - (Longitude / 15) -
EquationOfTime);
ShT[4] = BaseTime + (float)I4 / 60;

float alfa = r2d(-atan(1 / (1 + tan(d2r(fabs(Latitude - Declination))))));


float HA = HourAngle(alfa, Declination, Latitude);
ShT[5] = BaseTime + HA + (float)I5 / 60;

alfa = 0.8333f + 0.0347f * sqrt(Altitude);


HA = HourAngle(alfa, Declination, Latitude);
ShT[6] = BaseTime + HA + (float)I6 / 60;

ShT[2] = BaseTime - HA;


HA = HourAngle((float)18, Declination, Latitude);
ShT[7] = BaseTime + HA + (float)I7 / 60;

HA = HourAngle((float)20, Declination, Latitude);


ShT[1] = BaseTime - HA + (float)I1 / 60;

ShT[0] = ShT[1] - (float)10 / 60;

HA = HourAngle((float)-4.5, Declination, Latitude);


ShT[3] = BaseTime - HA;
}

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;
}

void check_azzan() {
SholatNow = -1;
for(int i=0; i <=7; i++) {
if(jamnow() >= ShT[i]){
SholatNow = i;
if(!azzan and (jamnow() > ShT[i]) and (jamnow() < (ShT[i]+0.03))) {
azzan =true;
RunS = 100;
}
}
}
}

void hijryCal(){
uint8_t date_cor = 0;
if (jamnow() > ShT[6]) {
date_cor = 1;
}
nowH = toHijri(now.year(), now.month(), now.day(), date_cor);
}

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;
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) {


hijir_date BuffDate;
long nday = Days(Y, M, D) + 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;
}

void AnimSquence() {
AnimJAM(30, 2000, 1);
dwMrq(drawDayDate(), 40, 1, 2);
AnimJAM(30, 2000, 3);

drawKBM(40, 4);
dwMrqMapel(40, 5);
AnimJAM(30, 2000, 6);

drawSholat(7);
AnimJAM(30, 2000, 8);
drawLokal(40, 9);

drawAzzan(100);
drawBell(50,101);

if (RunF == 1) {
RunS = 2;
RunF = 0;
}
if (RunF == 2) {
RunS = 3;
RunF = 0;
}
if (RunF == 3) {
if (hAktif) {
RunS = 4;
RunF = 0;
}
else {
RunS = 7;
RunF = 0;
}
}
if (RunF == 4) {
if (kamjum) {
RunS = 6;
RunF = 0;
}
else {
RunS = 5;
RunF = 0;
}
}
if (RunF == 5) {
RunS = 6;
RunF = 0;
}
if (RunF == 6) {
RunS = 7;
RunF = 0;
}
if (RunF == 7) {
if (hAktif) {
RunS = 8;
RunF = 0;
}
else {
RunS = 1;
RunF = 0;
}
}
if (RunF == 8) {
RunS = 9;
RunF = 0;
}
if (RunF == 9) {
RunS = 1;
RunF = 0;
}

if(RunF==100){
reset_x=1;
RunS = 1;
RunF =0;
}
if(RunF==101){
reset_x=1;
RunS = 1;
RunF =0;
}

if (DoSwap) {
Disp.swapBuffers();
}
}
void AnimJAM(int speed, int delay, int DrawAdd) {
if (!dwDo(DrawAdd)) return;
static uint8_t y;
static uint8_t s;
static uint16_t lsRn;
uint16_t Tmr = millis();
if ((Tmr - lsRn) > 30) {
if (s == 0 && y < 17) {
lsRn = Tmr;
y++;
}
if (s == 1 && y > 0) {
lsRn = Tmr;
y--;
}
}
if ((Tmr - lsRn) > 3000 && y == 17) {
s = 1;
}
if (y == 7) {
}
if (y == 0 && s == 1) {
dwDone(DrawAdd);
s = 0;
}
JAM_B(17 - y);
}

void JAM_B(uint16_t y) {
static uint16_t lsRn;
uint16_t Tmr = millis();
char BuffJ[6];
char BuffM[6];
char BuffD[6];
sprintf(BuffJ, "%02d", now.hour());
sprintf(BuffM, "%02d", now.minute());
sprintf(BuffD, "%s", ":");
Disp.setFont(fontAbesar);
Disp.drawText(0, y, BuffJ);
Disp.drawText(19, y, BuffM);
Disp.setFont(fontUmum);
if (Tmr - lsRn < 500) Disp.drawText(13, y + 5, BuffD);
if (Tmr - lsRn > 1000) lsRn = Tmr;
DoSwap = true;
}

void JAM_K(uint16_t y) {
static uint16_t lsRn;
uint16_t Tmr = millis();
char BuffJ[6];
char BuffM[6];
char BuffD[6];
sprintf(BuffJ, "%02d", now.hour());
sprintf(BuffM, "%02d", now.minute());
sprintf(BuffD, "%s", ":");
Disp.setFont(fontUmum);
Disp.drawText(0, y, BuffJ);
Disp.drawText(19, y, BuffM);
if (Tmr - lsRn < 500) Disp.drawText(13, y, BuffD);
if (Tmr - lsRn > 1000) lsRn = Tmr;
DoSwap = true;
}

void drawSholat_S(int sNum, int c) {


float stime = ShT[sNum];
uint8_t shour = floor(stime);
uint8_t sminute = floor((stime - (float) shour) * 60);
char BuffJ[6];
char BuffM[6];
char BuffD[6];
sprintf(BuffJ, "%02d", shour);
sprintf(BuffM, "%02d", sminute);
sprintf(BuffD, "%s", ":");
Disp.setFont(fontHkecil);
dwCtr(c, 0, NamaShalat(sNum));
Disp.setFont(fontUmum);
Disp.drawText(0, 9, BuffJ);
Disp.drawText(13, 9, BuffD);
Disp.drawText(19, 9, BuffM);
DoSwap = true;
}

void drawSholat(int DrawAdd) {


if (!dwDo(DrawAdd)) return;
static uint8_t x;
static uint8_t s;
static uint8_t sNum;
static uint16_t lsRn;
uint16_t Tmr = millis();
uint8_t c = 0;
uint8_t first_sNum = 0;
int DrawWd = Disp.width() - c;
if ((Tmr - lsRn) > 10) {
if (s == 0 && x < (DrawWd / 2)) {
x++;
lsRn = Tmr;
}
if (s == 1 && x > 0) {
x--;
lsRn = Tmr;
}
}
if ((Tmr - lsRn) > 1000 && x == (DrawWd / 2)) {
s = 1;
}
if (x == 0 && s == 1) {
if (sNum < 7) {
sNum++;
} else {
dwDone(DrawAdd);
sNum = 0;
}
s = 0;
}
drawSholat_S(sNum, c);
}

void dwMrq(const char * msg, int Speed, int dDT, int DrawAdd) {
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) + Disp.width();
uint16_t Tmr = millis();
if ((Tmr - lsRn) > Speed) {
lsRn = Tmr;
if (x < fullScroll) {
++x;
} else {
dwDone(DrawAdd);
x = 0;
return;
}
if (dDT == 1) {
if (x <= 6) {
JAM_K(x - 6);
} else if (x >= (fullScroll - 6)) {
JAM_K((fullScroll - x) - 6);
} else {
JAM_K(0);
}
Disp.setFont(fontUmum);
Disp.drawText(Disp.width() - x, 9, msg);
} else {
Disp.setFont(fontHbesar);
Disp.drawLine(1, 2, 62, 2);
Disp.drawLine(1, 13, 62, 13);
Disp.drawText(Disp.width() - x, 4, msg);
}
DoSwap = true;
}
}

void dwMrqMapel(int Speed, int DrawAdd) {


static uint16_t jpa = 1;
static uint16_t x;
static uint16_t lsRn;
uint16_t Tmr = millis();

if (!dwDo(DrawAdd)) return;
if (reset_x != 0) {
x = 0;
reset_x = 0;
}
if (formal) {
int fullScroll = Disp.textWidth(MAPELN(KegNow)) + Disp.width();
if ((Tmr - lsRn) > Speed) {
lsRn = Tmr;
if (x < fullScroll) {
++x;
} else {
dwDone(DrawAdd);
x = 0;
return;
}
Disp.setFont(fontHbesar);
Disp.drawLine(0, 0, 32, 0);
Disp.drawLine(0, 15, 32, 15);
Disp.drawText(Disp.width() - x, 3, MAPELN(KegNow));
DoSwap = true;
}
}
else {
int fullScroll = Disp.textWidth(MAPELN(jpa)) + Disp.width();
if ((Tmr - lsRn) > Speed) {
lsRn = Tmr;
if (x < fullScroll) {
++x;
} else {
x = 0;
jpa=jpa+1;
return;
}
if (jpa > 3) {
dwDone(DrawAdd);
jpa = 1;
}
Disp.setFont(fontUmum);
char J [2];
sprintf(J,"%0d", jpa);
Disp.drawText(0, 0, "JAM");
Disp.drawText(26, 0, J);
Disp.drawText(Disp.width() - x, 9, MAPELN(jpa));
DoSwap = true;
}
}
}

void drawKBM(int Speed, int DrawAdd) {


static uint16_t x;
static uint16_t lsRn;
static uint16_t keg = 1;
uint16_t Tmr = millis();
if (!dwDo(DrawAdd)) return;
if (reset_x != 0) {
x = 0;
reset_x = 0;
}
int fullScroll = Disp.textWidth(getKegiatan(keg, daynow())) + Disp.width();
if ((Tmr - lsRn) > Speed) {
lsRn = Tmr;
if (x < fullScroll) {
++x;
} else {
x = 0;
keg=keg+1;
return;
}
if (keg > 5) {
dwDone(DrawAdd);
keg = 1;
}

float stime = tKeg[keg];


uint8_t shour = floor(stime);
uint8_t sminute = floor((stime - (float) shour) * 60);
uint8_t ssecond = floor((stime-(float)shour-(float)sminute/60)*3600);
if (ssecond > 30) {ssecond = 0; sminute = sminute + 1;}
char BuffJ[6];
char BuffM[6];
char BuffD[6];
sprintf(BuffJ, "%02d", shour);
sprintf(BuffM, "%02d", sminute);
sprintf(BuffD, "%s", ":");

Disp.setFont(fontUmum);
Disp.drawText(0, 9, BuffJ);
Disp.drawText(13, 9, BuffD);
Disp.drawText(19, 9, BuffM);
Disp.drawText(Disp.width() - x, 0, getKegiatan(keg, daynow()));
DoSwap = true;
}
}

void drawLokal(int Speed, int DrawAdd) {


static uint16_t x;
static uint16_t lsRn;
static uint16_t start;
if (daynow() == 6) {
start = 6;
}
else {
start = 7;
}
static uint16_t keg = start;
uint16_t Tmr = millis();
if (!dwDo(DrawAdd)) return;
if (reset_x != 0) {
x = 0;
reset_x = 0;
}
int fullScroll = Disp.textWidth(getKegiatan(keg, daynow())) + Disp.width();
if ((Tmr - lsRn) > Speed) {
lsRn = Tmr;
if (x < fullScroll) {
++x;
} else {
x = 0;
keg=keg+1;
return;
}
if (keg > 11) {
dwDone(DrawAdd);
keg = start;
}

float stime = tKeg[keg];


uint8_t shour = floor(stime);
uint8_t sminute = floor((stime - (float) shour) * 60);
uint8_t ssecond = floor((stime-(float)shour-(float)sminute/60)*3600);
if (ssecond > 30) {ssecond = 0; sminute = sminute + 1;}
char BuffJ[6];
char BuffM[6];
char BuffD[6];
sprintf(BuffJ, "%02d", shour);
sprintf(BuffM, "%02d", sminute);
sprintf(BuffD, "%s", ":");

Disp.setFont(fontUmum);
Disp.drawText(0, 9, BuffJ);
Disp.drawText(13, 9, BuffD);
Disp.drawText(19, 9, BuffM);
Disp.drawText(Disp.width() - x, 0, getKegiatan(keg, daynow()));
DoSwap = true;
}
}

void drawAzzan(int DrawAdd) {


if (!dwDo(DrawAdd)) return;
uint8_t ct_limit = 40;
static uint8_t ct;
static uint16_t lsRn;
uint16_t Tmr = millis();
if ((Tmr - lsRn) > 500 && ct <= ct_limit) {
lsRn = Tmr;
if ((ct % 2) == 0) {
bitmapAdzan(0);
} else {}
DoSwap = true;
ct++;
}
if ((Tmr - lsRn) > 2000 && (ct > ct_limit)) {
dwDone(DrawAdd);
ct = 0;
}
}

void drawBell(int Speed, int DrawAdd) {


static uint16_t repeat = 1;
static uint16_t x;
static uint16_t lsRn;
uint16_t Tmr = millis();
if (!dwDo(DrawAdd)) return;
if (reset_x != 0) {
x = 0;
reset_x = 0;
}
int fullScroll = Disp.textWidth(getKegiatan(KegNow, daynow())) + Disp.width();
if ((Tmr - lsRn) > Speed) {
lsRn = Tmr;
if (x < fullScroll) {
++x;
} else {
x = 0;
repeat=repeat+1;
return;
}
if (repeat > 3) {
dwDone(DrawAdd);
repeat = 1;
}
Disp.setFont(fontUmum);
bitmapBell (0);
Disp.drawText(Disp.width() - x, 9, getKegiatan(KegNow, daynow()));
DoSwap = true;
}
}

boolean dwDo(int DrawAdd) {


return (RunS == DrawAdd);
}

void dwDone(int DrawAdd) {


RunF = DrawAdd;
RunS = 0;
}

void dwCtr(int x, int y, const char * Msg) {


int tw = Disp.textWidth(Msg);
int th = Disp.textHeight();
int c = int((Disp.width() - x - tw) / 2);
Disp.drawFilledRect(x + c - 1, y, x + tw + c, y + th, 0);
Disp.drawText(x + c, y, Msg);
}

void bitmapAdzan (uint16_t y)


{
static const uint8_t C[] PROGMEM =
{
32, 16,
B11111111,B11111111,B11111111,B11111111,
B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,
B00011000,B11100011,B11000110,B00100100,
B00100100,B10010000,B01001001,B00100100,
B00100100,B10010000,B01001001,B00110100,
B00100100,B10010000,B10001001,B00110100,
B00100100,B10010000,B10001001,B00101100,
B00111100,B10010001,B00001111,B00101100,
B00100100,B10010001,B00001001,B00100100,
B00100100,B10010010,B00001001,B00100100,
B00100100,B10010010,B00001001,B00100100,
B00100100,B11100011,B11001001,B00100100,
B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,
B11111111,B11111111,B11111111,B11111111
};
Disp.drawBitmap(0, y, C);
DoSwap = true;
}

void bitmapBell (uint16_t y)


{
static const uint8_t C[] PROGMEM =
{
32, 16,
B11111000,B11111100,B11000000,B00011100,
B11000100,B11000000,B11000000,B00100010,
B11000100,B11000000,B11000000,B01001001,
B11111000,B11111000,B11000000,B01010101,
B11000100,B11000000,B11000000,B01001001,
B11000100,B11000000,B11000000,B00100010,
B11111000,B11111100,B11111100,B00011100,
B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000
};
static uint16_t lsRn;
uint16_t Tmr = millis();
if (Tmr - lsRn < 500){
Disp.drawBitmap(0, y, C);
}
if (Tmr - lsRn > 1000){
lsRn = Tmr;
}
DoSwap = true;
}

const char static KEGIATAN[][16] PROGMEM = {


"",
"PELAJARAN 1",
"PELAJARAN 2",
"ISTIRAHAT",
"PELAJARAN 3",
"KBM SELESAI",
"EKSTRAKURIKULER",
"KEG M 1",
"KEG M 2",
"TIDUR MALAM",
"BANGUN MALAM",
"KEG M 3"
};

const char static KEG_MALAM[][16] PROGMEM = {


"",
"TILAWAH",
"TAHFIDZ",
"DZIKIR",
"TILAWAH",
"KAJIAN KITAB",
"DZIKIR",
"TILAWAH",
"MUHADHARAH",
"TAHFIDZ",
"TILAWAH",
"KAJIAN KITAB",
"DZIKIR",
"TILAWAH",
"TAHFIDZ",
"DZIKIR",
"AL KAHFI",
"KAJIAN UMUM",
"DZIKIR"
};

char* getKegiatan(int indexKegiatan, int hari) {


static char locBuff[16];
static char locBuffMalam[16];
memccpy_P(locBuff, KEGIATAN[indexKegiatan], 0, 16);
if (strcmp_P(locBuff, PSTR("KEG M 1")) == 0) {
int malamIndex = (hari == 1) ? 1 : 4;
memccpy_P(locBuffMalam, KEG_MALAM[malamIndex], 0, 16);
strcpy(locBuff, locBuffMalam);
} else if (strcmp_P(locBuff, PSTR("KEG M 2")) == 0) {
int malamIndex = (hari == 1) ? 2 : 5;
memccpy_P(locBuffMalam, KEG_MALAM[malamIndex], 0, 16);
strcpy(locBuff, locBuffMalam);
} else if (strcmp_P(locBuff, PSTR("KEG M 3")) == 0) {
int malamIndex = (hari == 1) ? 3 : 6;
memccpy_P(locBuffMalam, KEG_MALAM[malamIndex], 0, 16);
strcpy(locBuff, locBuffMalam);
}
return locBuff;
}

const char static MAPEL7[][11] PROGMEM = {


"",
"QURDIS",
"NAHWU",
"B. ARAB",
"B. ARAB",
"B. INDO",
"SKI",
"SHARF",
"M. HADIST",
"FIQIH",
"HADIST 101",
"IPS",
"MTK",
"BELAJAR",
"TAFSIR",
"FIQIH",
"TAUHID",
"MTK",
"AKHLAQ"
};

const char static MAPEL8[][11] PROGMEM = {


"",
"B. ARAB",
"QURDIS",
"NAHWU",
"SKI",
"B. ARAB",
"B. INDO",
"FIQIH",
"SHARF",
"M. HADIST",
"MTK",
"HADIST 101",
"IPS",
"FIQIH",
"BELAJAR",
"TAFSIR",
"AKHLAQ",
"TAUHID",
"MTK"
};
const char static MAPEL9[][11] PROGMEM = {
"",
"NAHWU",
"B. ARAB",
"QURDIS",
"B. INDO",
"SKI",
"B. ARAB",
"M. HADIST",
"FIQIH",
"SHARF",
"IPS",
"MTK",
"HADIST 101",
"TAFSIR",
"FIQIH",
"BELAJAR",
"MTK",
"AKHLAQ",
"TAUHID"
};

char* MAPELN(int number) {


static char locBuff7[11];
static char locBuff8[11];
static char locBuff9[11];
static char output[45];
if (jamnow() >= ShT[6]) {
number = number + ((3 * daynow() + 1) - 3);
} else {
number = number + ((3 * daynow()) - 3);
}
strcpy_P(locBuff7, MAPEL7[number]);
strcpy_P(locBuff8, MAPEL8[number]);
strcpy_P(locBuff9, MAPEL9[number]);
sprintf(output, "7tra. %s 8tra. %s 9tra. %s", locBuff7, locBuff8, locBuff9);
return output;
}

const char static sholatN_E[][6] PROGMEM = {


"IMSAK",
"SHUBH",
"SYURQ",
"DHUHA",
"DZUHR",
"ASHAR",
"MAGRB",
"ISYA'"
};

const char static h_month_E[][12] PROGMEM = {


"BLNH",
"MUHARRAM",
"SHAFAR",
"R.AWAL",
"R.TSANY",
"J.ULA",
"J.TSANY",
"RAJAB",
"SYA'BAN",
"RAMADHAN",
"SYAWAL",
"DZULQA'DAH",
"DZULHIJJAH"
};

const char static m_month_E[][4] PROGMEM = {


"BLN",
"JAN",
"FEB",
"MAR",
"APR",
"MEI",
"JUN",
"JUL",
"AGS",
"SEP",
"OKT",
"NOV",
"DES"
};

const char static DayName_E[][8] PROGMEM = {


"HARI",
"SABTU",
"AHAD",
"SENIN",
"SELASA",
"RABU",
"KAMIS",
"JUM'AT"
};

char* NamaShalat(int number) {


static char locBuff[6];
if (number >= 0 && number < sizeof(sholatN_E) / sizeof(sholatN_E[0])) {
memccpy_P(locBuff, sholatN_E[number], 0, 6);
}
return locBuff;
}

char* NamaHari(int number) {


static char locBuff[8];
if (number >= 0 && number < sizeof(DayName_E) / sizeof(DayName_E[0])) {
memccpy_P(locBuff, DayName_E[number], 0, 8);
}
return locBuff;
}

char* NamaBulanM(int number) {


static char locBuff[4];
if (number >= 0 && number < sizeof(m_month_E) / sizeof(m_month_E[0])) {
memccpy_P(locBuff, m_month_E[number], 0, 4);
}
return locBuff;
}
char* drawDayDate() {
char locBuff[12];
static char out[45];
int locLen = nowH.hM;
memccpy_P(locBuff, h_month_E[locLen], 0, 12);
sprintf(out, "%s, %02d %s %04d H * %02d %s %04d M", NamaHari(daynow()), nowH.hD,
locBuff, nowH.hY, now.day(), NamaBulanM(now.month()), now.year());
return out;
}

void cekaktif(){
if ((daynow() == 7 && jamnow() > ShT[2]) || (daynow() == 1 && jamnow() < ShT[2]))
{
hAktif = false;
formal = false;
ekskul = false;
klokal = false;
kamjum = false;
} else {
hAktif = true;
if ((jamnow() > 7 + (float)30/60 && jamnow() < 9 + (float)50/60) || (jamnow() >
10 + (float)20/60 && jamnow() < 11 + (float)30/60 )) {
formal = true;
} else {
formal = false;
}
if (jamnow() > ShT[5] && jamnow() < ShT[2]) {
klokal = true;
} else {
klokal = false;
}
if (daynow() == 6) {
ekskul = true;
} else {
ekskul = false;
}
if (daynow() == 6 && jamnow() >= jadnow(11,30)) {
kamjum = true;
} else {
kamjum = false;
}
}
}

void kegiatan() {
KegNow = 0;
tKeg[ 1] = jadnow( 7,30);
tKeg[ 2] = jadnow( 8,40);
tKeg[ 3] = jadnow( 9,50);
tKeg[ 4] = jadnow(10,20);
tKeg[ 5] = jadnow(11,30);
tKeg[ 6] = ShT[5] + (float) 10/60;
tKeg[ 7] = ShT[6] + (float) 10/60;
tKeg[ 8] = ShT[7] + (float) 10/60;
tKeg[ 9] = ShT[7] + 3 + (float) 30/60;
tKeg[10] = ShT[0] - (float) 20/60;
tKeg[11] = ShT[1] + (float) 10/60;
for (int i = 1; i < 12; i++) {
if (jamnow() >= tKeg[i] && jamnow() < tKeg[i + 1]) {
KegNow = i;
break;
}
}
}

bool belID[10] = {0,0,0,0,0,0,0,0,0,0};

void jadwalbel() {
if (hAktif == 1) {
jadbell( 1, 2, 1, 1);
jadbell( 2, 2, 1, 1);
jadbell( 3, 2, 1, 1);
jadbell( 4, 2, 1, 1);
jadbell( 5, 2, 1, 1);
jadbell( 9, 2, 1, 1);
jadbell(10, 2, 1, 1);
}
blink();
}

void jadbell(int ib, int fb, int pb, int db){


float toleransi = 5.0 / 3600.0;
if (jamnow() >= tKeg[ib] && jamnow() - tKeg[ib] < toleransi && belID[ib] == 0) {
ringbel(fb, pb, db);
belID[ib] = 1;
RunS = 101;
}
if (jamnow() > tKeg[ib] + toleransi) {
belID[ib] = 0;
}
}

void ringbel(int a, int b, int c) {


isBlinking = true;
blinkTarget = a;
onDuration = b * 1000;
offDuration = c * 1000;
blinkCount = 0;
belState = LOW;
Serial.println("LED ON");
Serial.println(now.minute());
digitalWrite(pinBel, belState);
prevMillisBel = millis();
}

void blink() {
if (isBlinking) {
unsigned long currentMillisBel = millis();
if (belState == LOW && (currentMillisBel - prevMillisBel >= onDuration)) {
prevMillisBel = currentMillisBel;
belState = HIGH;
digitalWrite(pinBel, belState);
Serial.println("LED OFF");
} else if (belState == HIGH && (currentMillisBel - prevMillisBel >=
offDuration)) {
prevMillisBel = currentMillisBel;
belState = LOW;
digitalWrite(pinBel, belState);
Serial.println("LED ON");
blinkCount++;
}
if (blinkCount >= blinkTarget) {
isBlinking = false;
digitalWrite(pinBel, HIGH);
Serial.println("LED OFF");
Serial.println("====");
}
}
}

You might also like