#define pinLedMerah 5
#define pinLedHijau 6
#define pinLedBiru 7
#define pinTombolOtomatis 11
#define pinTombolManual 12
#define pinTombolJammer 13
#define pinJammer 4
#define relayOn LOW
#define waktuJammerShalat 20
#define waktuJammerShalatJumat 60
#define waktuJammerManual 20
#include <Wire.h>
#include "Sodaq_DS3231.h"
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 16, 2);
struct
waktu
{
byte jam;
byte menit;
};
const
waktu jadwalShalat[][8] PROGMEM = {
{{ 4, 20}, { 4, 30}, { 5, 51}, { 6, 15}, {12, 7}, {15, 34}, {18, 20}, {19, 36}},
{{ 4, 20}, { 4, 30}, { 5, 51}, { 6, 15}, {12, 8}, {15, 34}, {18, 20}, {19, 36}},
{{ 4, 21}, { 4, 31}, { 5, 52}, { 6, 16}, {12, 8}, {15, 35}, {18, 21}, {19, 36}},
{{ 4, 21}, { 4, 31}, { 5, 52}, { 6, 16}, {12, 9}, {15, 35}, {18, 21}, {19, 37}},
{{ 4, 22}, { 4, 32}, { 5, 53}, { 6, 17}, {12, 9}, {15, 36}, {18, 21}, {19, 37}},
{{ 4, 23}, { 4, 33}, { 5, 53}, { 6, 17}, {12, 9}, {15, 36}, {18, 22}, {19, 37}},
{{ 4, 23}, { 4, 33}, { 5, 54}, { 6, 18}, {12, 10}, {15, 36}, {18, 22}, {19, 38}},
{{ 4, 24}, { 4, 34}, { 5, 54}, { 6, 18}, {12, 10}, {15, 37}, {18, 23}, {19, 38}},
{{ 4, 24}, { 4, 34}, { 5, 55}, { 6, 19}, {12, 11}, {15, 37}, {18, 23}, {19, 38}},
{{ 4, 25}, { 4, 35}, { 5, 55}, { 6, 19}, {12, 11}, {15, 37}, {18, 23}, {19, 38}},
{{ 4, 25}, { 4, 35}, { 5, 56}, { 6, 20}, {12, 12}, {15, 37}, {18, 24}, {19, 39}},
{{ 4, 26}, { 4, 36}, { 5, 56}, { 6, 20}, {12, 12}, {15, 38}, {18, 24}, {19, 39}},
{{ 4, 27}, { 4, 37}, { 5, 56}, { 6, 20}, {12, 12}, {15, 38}, {18, 24}, {19, 39}},
{{ 4, 27}, { 4, 37}, { 5, 57}, { 6, 21}, {12, 13}, {15, 38}, {18, 25}, {19, 39}},
{{ 4, 28}, { 4, 38}, { 5, 57}, { 6, 21}, {12, 13}, {15, 38}, {18, 25}, {19, 40}},
{{ 4, 28}, { 4, 38}, { 5, 58}, { 6, 22}, {12, 13}, {15, 39}, {18, 25}, {19, 40}},
{{ 4, 29}, { 4, 39}, { 5, 58}, { 6, 22}, {12, 14}, {15, 39}, {18, 25}, {19, 40}},
{{ 4, 29}, { 4, 39}, { 5, 59}, { 6, 23}, {12, 14}, {15, 39}, {18, 26}, {19, 40}},
{{ 4, 30}, { 4, 40}, { 5, 59}, { 6, 23}, {12, 14}, {15, 39}, {18, 26}, {19, 40}},
{{ 4, 30}, { 4, 40}, { 5, 59}, { 6, 23}, {12, 15}, {15, 39}, {18, 26}, {19, 40}},
{{ 4, 31}, { 4, 41}, { 6, 0}, { 6, 24}, {12, 15}, {15, 39}, {18, 26}, {19, 40}},
{{ 4, 31}, { 4, 41}, { 6, 0}, { 6, 24}, {12, 15}, {15, 39}, {18, 26}, {19, 40}},
{{ 4, 32}, { 4, 42}, { 6, 1}, { 6, 25}, {12, 16}, {15, 39}, {18, 27}, {19, 41}},
{{ 4, 32}, { 4, 42}, { 6, 1}, { 6, 25}, {12, 16}, {15, 39}, {18, 27}, {19, 41}},
{{ 4, 33}, { 4, 43}, { 6, 1}, { 6, 25}, {12, 16}, {15, 39}, {18, 27}, {19, 41}},
{{ 4, 33}, { 4, 43}, { 6, 2}, { 6, 26}, {12, 16}, {15, 39}, {18, 27}, {19, 41}},
{{ 4, 34}, { 4, 44}, { 6, 2}, { 6, 26}, {12, 17}, {15, 39}, {18, 27}, {19, 41}},
{{ 4, 34}, { 4, 44}, { 6, 2}, { 6, 26}, {12, 17}, {15, 39}, {18, 27}, {19, 41}},
{{ 4, 35}, { 4, 45}, { 6, 3}, { 6, 27}, {12, 17}, {15, 39}, {18, 27}, {19, 40}},
{{ 4, 35}, { 4, 45}, { 6, 3}, { 6, 27}, {12, 17}, {15, 39}, {18, 27}, {19, 40}},
{{ 4, 36}, { 4, 46}, { 6, 3}, { 6, 27}, {12, 17}, {15, 39}, {18, 27}, {19, 40}},
};
byte waktuUtama[] = {1, 4, 5, 6, 7};
char
namaHari[][8] = {
"Minggu,"
,
"Senin, "
,
"Selasa,"
,
" Rabu, "
,
"Kamis, "
,
"Jumat, "
,
"Sabtu, "
};
char
namaWaktu[][16] = {
"Imsyak"
,
"Shubuh"
,
"Terbit"
,
"Dhuha"
,
"Dzuhur"
,
"Ashr"
,
"Maghrib"
,
"Isya"
};
enum
Mode
{
otomatis,
manual,
};
byte mode;
char
buffer[32];
byte detikSebelumnya = 60;
byte menitSebelumnya = 60;
uint16_t
unixRelay;
bool
statusJammer;
DateTime now;
void
setup()
{
pinMode(pinLedMerah, OUTPUT);
pinMode(pinLedHijau, OUTPUT);
pinMode(pinLedBiru, OUTPUT);
digitalWrite(pinJammer, !relayOn);
pinMode(pinJammer, OUTPUT);
pinMode(pinTombolOtomatis, INPUT_PULLUP);
pinMode(pinTombolManual, INPUT_PULLUP);
pinMode(pinTombolJammer, INPUT_PULLUP);
Serial.begin(9600);
Serial.println(
"JWS Jammer Sinyal HP dengan Jadwal Bulanan"
);
Wire.begin();
Wire.beginTransmission(0x3F);
if
(Wire.endTransmission())
{
lcd = LiquidCrystal_I2C(0x27, 16, 2);
}
lcd.begin();
rtc.begin();
now = rtc.now();
if
(now.year() == 2000)
{
char
bulan[12];
byte indexBulan;
int
jam, menit, detik, tanggal, tahun;
char
*namaBulan[12] = {
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sep"
,
"Oct"
,
"Nov"
,
"Dec"
};
sscanf
(__TIME__,
"%d:%d:%d"
, &jam, &menit, &detik);
sscanf
(__DATE__,
"%s %d %d"
, bulan, &tanggal, &tahun);
for
(indexBulan = 0; indexBulan < 12; indexBulan++) {
if
(
strcmp
(bulan, namaBulan[indexBulan]) == 0)
break
;
}
uint8_t
wday = hariDariTanggal(tanggal, indexBulan + 1, tahun);
DateTime dt(tahun, indexBulan + 1, tanggal, jam, menit, detik, wday);
rtc.setDateTime(dt);
Serial.println(
"RTC sudah otomatis di setting (Sekali saja)"
);
}
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print(
"JWS Bulanan"
);
lcd.setCursor(0, 1);
lcd.print(
"fitur : Jammer"
);
delay(3000);
lcd.clear();
digitalWrite(pinLedHijau, HIGH);
Serial.println(
"Sistem mulai"
);
}
void
loop()
{
now = rtc.now();
uint16_t
unixSekarang = now.hour() * 60 + now.minute();
if
(detikSebelumnya != now.second())
{
detikSebelumnya = now.second();
if
(!statusJammer)
{
sprintf
(buffer,
"%s %02d/%02d/%02d"
, namaHari[now.dayOfWeek() - 1], now.date(), now.month(), now.year() - 2000);
lcd.setCursor(0, 0);
lcd.print(buffer);
}
sprintf
(buffer,
"%02d:%02d:%02d"
, now.hour(), now.minute(), now.second());
lcd.setCursor(4, 1);
lcd.print(buffer);
}
if
(menitSebelumnya != now.minute())
{
menitSebelumnya = now.minute();
if
(mode == otomatis)
{
for
(byte i = 0; i < 5; i++)
{
if
((pgm_read_byte(&jadwalShalat[now.date() - 1][waktuUtama[i]].jam) == now.hour()) &&
(pgm_read_byte(&jadwalShalat[now.date() - 1][waktuUtama[i]].menit) == now.minute()))
{
digitalWrite(pinLedMerah, HIGH);
digitalWrite(pinJammer, relayOn);
if
((i == 1) && (now.dayOfWeek() == 6))
{
unixRelay = unixSekarang + waktuJammerShalatJumat;
}
else
{
unixRelay = unixSekarang + waktuJammerShalat;
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(
" J A M M E R "
);
statusJammer =
true
;
sprintf
(buffer,
"Waktu: %s"
, namaWaktu[waktuUtama[i]]);
lcd.setCursor(0, 1);
lcd.print(buffer);
delay(5000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(
" J A M M E R "
);
}
}
}
if
(statusJammer)
{
if
(unixSekarang == unixRelay)
{
statusJammer =
false
;
digitalWrite(pinLedMerah, LOW);
digitalWrite(pinJammer, !relayOn);
}
}
}
if
(!digitalRead(pinTombolOtomatis))
{
delay(50);
if
(!digitalRead(pinTombolOtomatis))
{
mode = otomatis;
digitalWrite(pinLedHijau, HIGH);
digitalWrite(pinLedBiru, LOW);
lcd.setCursor(0, 0);
lcd.print(
" M O D E "
);
lcd.setCursor(0, 1);
lcd.print(
"O T O M A T I S "
);
delay(3000);
lcd.clear();
}
}
if
(!digitalRead(pinTombolManual))
{
delay(50);
if
(!digitalRead(pinTombolManual))
{
mode = manual;
digitalWrite(pinLedHijau, LOW);
digitalWrite(pinLedBiru, HIGH);
lcd.setCursor(0, 0);
lcd.print(
" M O D E "
);
lcd.setCursor(0, 1);
lcd.print(
" M A N U A L "
);
delay(3000);
lcd.clear();
}
}
if
(mode == manual)
{
if
(!digitalRead(pinTombolJammer))
{
delay(50);
if
(!digitalRead(pinTombolJammer))
{
if
(statusJammer)
{
digitalWrite(pinLedMerah, LOW);
digitalWrite(pinJammer, !relayOn);
statusJammer =
false
;
}
else
{
digitalWrite(pinLedMerah, HIGH);
digitalWrite(pinJammer, relayOn);
unixRelay = unixSekarang + waktuJammerManual;
statusJammer =
true
;
lcd.setCursor(0, 0);
lcd.print(
" J A M M E R "
);
lcd.setCursor(0, 1);
lcd.print(
" M A N U A L "
);
delay(5000);
}
while
(!digitalRead(pinTombolJammer));
delay(50);
}
}
}
}
byte hariDariTanggal(byte tanggal, byte bulan,
uint16_t
tahun)
{
uint16_t
jumlahHariPerBulanMasehi[] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
if
(tahun >= 2000)
tahun -= 2000;
uint32_t
jumlahHari = tahun * 365;
uint16_t
tahunKabisat = tahun / 4;
for
(byte i = 0; i < tahun; i++)
{
if
(!(i % 4))
{
jumlahHari++;
}
}
jumlahHari += jumlahHariPerBulanMasehi[bulan - 1];
if
( (bulan >= 2) && !(tahun % 4))
{
jumlahHari++;
}
jumlahHari += tanggal;
return
((jumlahHari + 5) % 7) + 1;
}