Rabu, 10 Agustus 2016

Jadwal Shalat Sesi 4

Lanjutan Sesi 3


Halaman ini adalah lanjutan dari praktek Membuat Jadwal Shalat Abadi dengan mikrokontroller Arduino. Prinsipnya ialah kita memasukan data jadwal Shalat ke dalam program kemudian kita tampilkan sesuai dengan tanggal yang sekarang jadi lebih memudahkan kepada pemilik alat dalam melihat Jadwal Shalat. Pada Prinsipny Cara kerja alat nya sama. Perbedaannya hanya sedikiiiit.. coba dimana. Uplod dulu aja programnya. kemudian coba tekan tombol demi tombol nya.. Pasti ketemu perbedaannya


------------------------------------------------------------------------------------------
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);  // RS,E,D4,D5,D6,D7

#include "Wire.h"
#define DS1307_ADDRESS 0x68
byte zero = 0x00; //workaround for issue #527
int ct1=1;
int ta=9 ; int tb=8; int tc=7;
int t1,t2,t3,j,mn,d,tg,bl,th,hk,tg2;
String hari;
String b1,b2,baris1,baris2;
int k=1; int tm=1;
int j1,j2,m1,m2,d1,d2;
int ct2,ct3,ht;
boolean lt1= false;
boolean lt3= false;
boolean lt2= false;
boolean jshalat= true;


int Bulan,tgl,sh,is,dz,as,mg;
int menitisya1,menitisya2,menitshubuh1,menitshubuh2,menitzhuhur1,menitzhuhur2;
int menitashar1,menitashar2,menitmaghrib1,menitmaghrib2;
int menitisya,menitshubuh,menitzhuhur,menitashar,menitmaghrib;

int jamisya1,jamisya2,jamshubuh1,jamshubuh2,jamzhuhur1,jamzhuhur2;
int jamashar1,jamashar2,jammaghrib1,jammaghrib2;
int jamisya,jamshubuh,jamzhuhur,jamashar,jammaghrib;

String isya,shubuh,zhuhur, ashar, maghrib;

void setup() {
    Wire.begin();
    lcd.begin(16,2);
  pinMode(ta,INPUT); pinMode(tb,INPUT);pinMode(tc,INPUT);
}

void loop() {
 delay(100);
  t1= digitalRead(ta);
  t2= digitalRead(tb);
  t3= digitalRead(tc);

  if (k==1) {
  Wire.beginTransmission(DS1307_ADDRESS);
  byte zero = 0x00;
  Wire.write(zero);
  Wire.endTransmission();
  Wire.requestFrom(DS1307_ADDRESS, 7);
   d = bcdToDec(Wire.read());
  mn = bcdToDec(Wire.read());
  j = bcdToDec(Wire.read() & 0b111111); //24 hour time
  hk = bcdToDec(Wire.read()); //0-6 -> sunday - Saturday
  tg = bcdToDec(Wire.read());
  bl = bcdToDec(Wire.read());
  th = bcdToDec(Wire.read());
    j1= j/10; j2=j%10; m1=mn/10; m2=mn%10; d1=d/10; d2=d%10;
 if (t1 ==1 && lt1 == false) { 
   ct1+=1; if (ct1>19) {k=2;tm=1;ct1=1; lt1= true ;} }
  else ct1=1;
  if (t3==1 && lt3== false ){k=3;tm=1; lt3= true; }
 if (t2==1 && lt2== false ){k=3;tm=2; lt3= true; }


   baris1= "Jam : "+String (j1)+String (j2) +":"+ String (m1)+String (m2)+":"+String (d1)+String (d2) ;
if (jshalat==true){
  ct3 +=1; if (ct3 >22) {ct3=1; ht+=1; if (ht>8) ht=1;}
  if (ht==1)   baris2 = hari+ " "+ String (tg) +"-"+ String (bl)+"-20"+ String (th) ;
   if (ht==2)   baris2 = "Jadwal Shalat" ;
   if (ht==3)   baris2 = "Isya :" + isya;
   if (ht==4)   baris2 = "Shubuh :" + shubuh; ;
   if (ht==5)   baris2 = "Zhuhur :"+ zhuhur ;
   if (ht==6)   baris2 = "Ashar :"+ ashar ;
   if (ht==7)   baris2 ="Maghrib :" + maghrib ;
   if (ht==8)   baris2 = "Terima Kasih" ; }
  else baris2= hari+ " "+ String (tg) +"-"+ String (bl)+"-20"+ String (th) ;
 }

if (k==2) {
if (tm==1){
  baris1 ="Memasuki Menu ";
   baris2 = "Pengaturan Alat ";
   ct1 +=1;
   if (ct1 > 10) {ct1=0;  tm=2;   }
}
if (tm==2){
  baris1 ="2. Rubah Waktu ";
   baris2 = "3. Keluar ";
  if (t2==1 ) {tm=3; }
 if (t3==1 ) {tm=1; k=1; }
  if (t1==0) lt1= false;
 }
if (tm==3){
  baris1 ="Memasuki Menu ";
   baris2 = "Merubah Data Jam ";
   ct1 +=1;
   if (ct1 > 10) {ct1=0;  tm=4;   }
}


if (tm==4){
  baris1  ="Jam : "+String(j) ;
  baris2 ="1.Next 2&3 Atur";
  if (t2==1 ) {j+=1; if(j>23) j=0;}
 if (t3==1 ) {j-=1; if(j<0) j=23;}
 if (t1==1 && lt1== false) { tm=5; lt1=true; }
 if (t1==0) lt1= false;
}
if (tm==5){
  baris1  ="Menit : "+String(mn) ;
  baris2 ="1.Next 2&3 Atur";
  if (t2==1 ) {mn+=1; if(mn>59) mn=0;}
 if (t3==1 ) {mn-=1; if(mn<0) mn=59;}
 if (t1==1 && lt1 == false) { tm=6; lt1=true; }
 if (t1==0) lt1= false;
}
if (tm==6){
  baris1 ="Memasuki Menu ";
   baris2 = "Merubah Tanggal";
   ct1 +=1;
   if (ct1 > 10) {ct1=0;  tm=7;   }
}
if (tm==7){
  baris1  ="Tanggal : "+ String(tg) ;
  baris2 ="1.Next 2&3 Atur";
  if (t2==1 ) {tg+=1; if(tg>31) tg=1;}
 if (t3==1 ) {tg-=1; if(tg<1) tg=31;}
 if (t1==1 && lt1 == false) { tm=8; lt1=true; }
 if (t1==0) lt1= false;
}
 if (tm==8){
  baris1  = "Bulan : "+ String(bl) ;
  baris2 = "1.Next 2&3 Atur";
  if (t2==1 ) {bl+=1; if(bl>12) bl=1;}
 if (t3==1 ) {bl-=1; if(bl<1) bl=12;}
 if (t1==1 && lt1 == false) { tm=9; lt1=true; }
 if (t1==0) lt1= false;
}
if (tm==9){
  baris1  = "Tahun : "+ String(th) ;
  baris2 = "1.Next 2&3 Atur";
  if (t2==1 ) {th+=1; if(th>99) th=1;}
 if (t3==1 ) {th-=1; if(th<1) th=99;}
 if (t1==1 && lt1 == false) { tm=10; lt1=true; }
 if (t1==0) lt1= false;
}

 if (tm==10){
  baris1  = "Hari : "+ String(hari) ;
  baris2 = "1.Next 2&3 Atur";
  if (t2==1 ) {hk +=1; if(hk>6 ) hk=1;}
 if (t3==1 ) {hk -=1; if(hk<1) hk=6;}
 if (t1==1 && lt1 == false) { tm=11; lt1=true; }
 if (t1==0) lt1= false;
}

if (tm== 11){
   baris1 ="Data dirubah...?";
   baris2= "2. Ya   3. Tidak ";
if (t1==0) lt1= false;
  if (t3==1 ){ tm=1;k=1;}
 if (t2==1 ) {tm=1;k=1;
   Wire.beginTransmission(DS1307_ADDRESS);
  Wire.write(zero); //stop Oscillator
  Wire.write(decToBcd(1));
  Wire.write(decToBcd(mn));
  Wire.write(decToBcd(j));
  Wire.write(decToBcd(hk));
  Wire.write(decToBcd(tg));
  Wire.write(decToBcd(bl));
  Wire.write(decToBcd(th));
  Wire.write(zero); //start
  Wire.endTransmission();
  delay (100);
 }}

 delay (155);
 } // END OF K2

// Cek tanggal RTC dan sesuaikan jadwal Shalat dengan tanggal
if (tg != tg2 ) { tg2=tg;
tgl=tg ; Bulan =bl;

if (Bulan ==1) {
if (tgl < 5 ) { sh = 418; dz = 1159; as =1525 ; mg = 1813 ; is = 1928 ;}
if (tgl >4 ){ sh = 420; dz = 1201; as =1527 ; mg = 1814 ; is = 1929 ;}
if (tgl>9 ){ sh = 423; dz = 1203; as =1528 ; mg = 1816 ; is = 1931 ;}
if (tgl >14 ){ sh = 426; dz = 1205; as =1529 ; mg = 1818 ; is = 1932 ;}
if (tgl >19 ){ sh = 420; dz = 1207; as =1530 ; mg = 1819 ; is = 1932 ;}
if (tgl > 24 ){ sh = 432; dz = 1208; as =1530 ; mg = 1820 ; is = 1932 ;}
if (tgl>27 ) { sh = 433; dz = 1209; as =1530 ; mg = 1820 ; is = 1933 ;}
if (tgl>30 ){ sh = 434; dz = 1209; as =1530 ; mg = 1820 ; is = 1933 ;}
}

if (Bulan ==2) {
if (tgl<5) { sh = 435; dz = 1209; as =1529 ; mg = 1820 ; is = 1932 ;}
if (tgl>4) { sh = 437; dz = 1210; as =1528 ; mg = 1820 ; is = 1931 ;}
if (tgl>9){ sh = 438; dz = 1210; as =1526 ; mg = 1820 ; is = 1930 ;}
if (tgl>14){ sh = 440; dz = 1210; as =1523 ; mg = 1819 ; is = 1929 ;}
if (tgl>19){ sh = 441; dz = 1210; as =1520 ; mg = 1817 ; is = 1927 ;}
if (tgl>24) { sh = 442; dz = 1209; as =1518 ; mg = 1816 ; is = 1925 ;}
if (tgl>27){ sh = 442; dz = 1208; as =1514 ; mg = 1815 ; is = 1924 ;}
}

if (Bulan ==3) {
if (tgl<5){ sh = 441; dz = 1208; as =1512 ; mg = 1814 ; is = 1923 ;}
if (tgl>4){ sh = 442; dz = 1207; as =1507 ; mg = 1813 ; is = 1921 ;}
if (tgl>9) { sh = 441; dz = 1206; as =1509 ; mg = 1811 ; is = 1919 ;}
if (tgl>14){ sh = 441; dz = 1204; as =1511 ; mg = 1808 ; is = 1916 ;}
if (tgl>19){ sh = 441; dz = 1203; as =1512 ; mg = 1806 ; is = 1914 ;}
if (tgl>24) { sh = 440; dz = 1201; as =1513 ; mg = 1804 ; is = 1912 ;}
if (tgl>30) { sh = 439; dz = 1159; as =1513 ; mg = 1801 ; is = 1909 ;}
}

if (Bulan ==4) {
if (tgl<5){ sh = 439; dz = 1159; as =1514 ; mg = 1800 ; is = 1908 ;}
if (tgl>4){ sh = 438; dz = 1158; as =1514 ; mg = 1759 ; is = 1907 ;}
if (tgl>9) { sh = 438; dz = 1157; as =1514 ; mg = 1756 ; is = 1905 ;}
if (tgl>14) { sh = 437; dz = 1155; as =1514 ; mg = 1754 ; is = 1903 ;}
if (tgl>19){ sh = 436; dz = 1154; as =1514 ; mg = 1753 ; is = 1902 ;}
if (tgl>24) { sh = 435; dz = 1151; as =1514 ; mg = 1751 ; is = 1900 ;}
if (tgl>30) { sh = 435; dz = 1153; as =1513 ; mg = 1750 ; is = 1900 ;}
}

if (Bulan ==5) {
if (tgl<5){ sh = 435; dz = 1153; as =1513 ; mg = 1749 ; is = 1859 ;}
if (tgl>4){ sh = 435; dz = 1152; as =1513 ; mg = 1748 ; is = 1859 ;}
if (tgl>9){ sh = 434; dz = 1152; as =1513 ; mg = 1748 ; is = 1858 ;}
if (tgl>14){ sh = 434; dz = 1152; as =1513 ; mg = 1747 ; is = 1859 ;}
if (tgl>19){ sh = 435; dz = 1152; as =1514 ; mg = 1747 ; is = 1859 ;}
if (tgl>24) { sh = 435; dz = 1153; as =1514 ; mg = 1747 ; is = 1859 ;}
if (tgl> 30) { sh = 436; dz = 1154; as =1516 ; mg = 1747 ; is = 1900 ;}
}
if (Bulan ==6) {
if (tgl<5){ sh = 436; dz = 1154; as =1515 ; mg = 1747 ; is = 1900 ;}
if (tgl>4) { sh = 436; dz = 1154; as =1516 ; mg = 1748 ; is = 1901 ;}
if (tgl>9){ sh = 436; dz = 1155; as =1517 ; mg = 1748 ; is = 1902 ;}
if (tgl>14){ sh = 438; dz = 1157; as =1518 ; mg = 1749 ; is = 1903 ;}
if (tgl>9){ sh = 439; dz = 1158; as =1519 ; mg = 1750 ; is = 1904 ;}
if (tgl>24) { sh = 441; dz = 1159; as =1520 ; mg = 1751 ; is = 1905 ;}
if (tgl>30) { sh = 442; dz = 1200; as =1521 ; mg = 1752 ; is = 1906 ;}
}

if (Bulan ==7) {
if (tgl<5 ) { sh = 442; dz = 1200; as =1521 ; mg = 1753 ; is = 1906 ;}
if (tgl>4 ){ sh = 443; dz = 1201; as =1522 ; mg = 1754 ; is = 1907 ;}
if (tgl>9){ sh = 444; dz = 1201; as =1523 ; mg = 1754 ; is = 1908 ;}
if (tgl>14) { sh = 444; dz = 1102; as =1523 ; mg = 1755 ; is = 1908 ;}
if (tgl>19){ sh = 444; dz = 1202; as =1524 ; mg = 1756 ; is = 1908 ;}
if (tgl>24) { sh = 444; dz = 1202; as =1524 ; mg = 1757 ; is = 1909 ;}
if (tgl>27){ sh = 444; dz = 1202; as =1524 ; mg = 1757 ; is = 1908 ;}
}

if (Bulan ==8) {
if (tgl<5){ sh = 444; dz = 1202; as =1523 ; mg = 1753 ; is = 1906 ;}
if (tgl>4){ sh = 444; dz = 1202; as =1523 ; mg = 1754 ; is = 1907 ;}
if (tgl>9){ sh = 443; dz = 1201; as =1522 ; mg = 1754 ; is = 1908 ;}
if (tgl>14){ sh = 442; dz = 1200; as =1520 ; mg = 1755 ; is = 1908 ;}
if (tgl>19){ sh = 441; dz = 1159; as =1519 ; mg = 1756 ; is = 1908 ;}
if (tgl>24) { sh = 439; dz = 1157; as =1517 ; mg = 1757 ; is = 1909 ;}
if (tgl>27){ sh = 437; dz = 1156; as =1515 ; mg = 1757 ; is = 1908 ;}
}

if (Bulan ==9) {
if (tgl<5) { sh = 436; dz = 1155; as =1513 ; mg = 1755 ; is = 1903 ;}
if (tgl>4){ sh = 435; dz = 1154; as =1511 ; mg = 1754 ; is = 1902 ;}
if (tgl>9){ sh = 432; dz = 1152; as =1507 ; mg = 1753 ; is = 1901 ;}
if (tgl>14){ sh = 430; dz = 1150; as =1504 ; mg = 1752 ; is = 1900 ;}
if (tgl>19){ sh = 427; dz = 1149; as =1500 ; mg = 1751 ; is = 1859 ;}
if (tgl>24) { sh = 425; dz = 1147; as =1456 ; mg = 1750 ; is = 1858 ;}
if (tgl>27) { sh = 422; dz = 1145; as =1503 ; mg = 1749 ; is = 1857 ;}
}


if (Bulan ==10) {
if (tgl<5){ sh = 421; dz = 1145; as =1451 ; mg = 1749 ; is = 1857 ;}
if (tgl>4){ sh = 419; dz = 1144; as =1447 ; mg = 1749 ; is = 1857 ;}
if (tgl>9){ sh = 419; dz = 1144; as =1445 ; mg = 1750 ; is = 1857 ;}
if (tgl>14) { sh = 414; dz = 1141; as =1446 ; mg = 1758 ; is = 1857 ;}
if (tgl>19){ sh = 412; dz = 1140; as =1449 ; mg = 1758 ; is = 1857 ;}
if (tgl>24) { sh = 410; dz = 1140; as =1451 ; mg = 1758 ; is = 1857 ;}
if (tgl>27){ sh = 409; dz = 1139; as =1453 ; mg = 1748 ; is = 1858 ;}
if (tgl>30){ sh = 409; dz = 1139; as =1453 ; mg = 1748 ; is = 1858 ;}
}


if (Bulan ==11) {
if (tgl<5) { sh = 408; dz = 1139; as =1455 ; mg = 1749 ; is = 1859 ;}
if (tgl>4) { sh = 407; dz = 1139; as =1456 ; mg = 1749 ; is = 1900 ;}
if (tgl>9){ sh = 406; dz = 1140; as =1459 ; mg = 1750 ; is = 1902 ;}
if (tgl>14){ sh = 405; dz = 1141; as =1501 ; mg = 1758 ; is = 1904 ;}
if (tgl>19){ sh = 405; dz = 1142; as =1504 ; mg = 1758 ; is = 1907 ;}
if (tgl>24){ sh = 405; dz = 1143; as =1507 ; mg = 1756 ; is = 1909 ;}
if (tgl>30){ sh = 406; dz = 1145; as =1509 ; mg = 1758 ; is = 1912 ;}
}

if (Bulan ==12) {
if (tgl<5){ sh = 406; dz = 1145; as =1510 ; mg = 1759 ; is = 1813 ;}
if (tgl>4){ sh = 407; dz = 1147; as =1512 ; mg = 1800 ; is = 1915 ;}
if (tgl>9){ sh = 409; dz = 1149; as =1515 ; mg = 1803 ; is = 1918 ;}
if (tgl>14) { sh = 411; dz = 1152; as =1518 ; mg = 1806 ; is = 1921 ;}
if (tgl>19){ sh = 413; dz = 1154; as =1521 ; mg = 1808 ; is = 1923 ;}
if (tgl>24){ sh = 415; dz = 1156; as =1523 ; mg = 1811 ; is = 1926 ;}
if (tgl>30){ sh = 418; dz = 1159; as =1525 ; mg = 1813 ; is = 1928 ;}
}

jamshubuh=sh/100; jamshubuh1=jamshubuh/10; jamshubuh2=jamshubuh%10 ;
menitshubuh =sh%100;menitshubuh1 =menitshubuh /10; menitshubuh2 =menitshubuh %10;
shubuh =  String(jamshubuh1) + String(jamshubuh2) +":" + String(menitshubuh1) + String(menitshubuh2);

jamzhuhur =dz/100; jamzhuhur1= jamzhuhur/10; jamzhuhur2=jamzhuhur%10 ;
menitzhuhur =dz%100; menitzhuhur1 =menitzhuhur /10; menitzhuhur2 =menitzhuhur %10;
zhuhur = String(jamzhuhur1) + String(jamzhuhur2) +":" + String(menitzhuhur1) + String(menitzhuhur2);

jamashar =as /100; jamashar1= jamashar/10; jamashar2=jamashar%10 ;
menitashar =as %100; menitashar1 =menitashar /10; menitashar2 =menitashar %10;
ashar = String(jamashar1) + String(jamashar2) +":" + String(menitashar1) + String(menitashar2);

jammaghrib =mg /100; jammaghrib1= jammaghrib/10; jammaghrib2=jammaghrib%10 ;
menitmaghrib =mg %100; menitmaghrib1 =menitmaghrib /10; menitmaghrib2 =menitmaghrib %10;
maghrib = String(jammaghrib1) + String(jammaghrib2) +":" + String(menitmaghrib1) + String(menitmaghrib2);

jamisya =is /100; jamisya1= jamisya/10; jamisya2=jamisya%10 ;
menitisya =is %100; menitisya1 =menitisya /10; menitisya2 =menitisya %10;
isya = String(jamisya1) + String(jamisya2) +":" + String(menitisya1) + String(menitisya2);

}

if (k==3) {
  if (tm==1){
    if (t3==0) lt3=false;
    baris1="Rubah Tampilan";
    baris2 ="Jam + Jdw Shalat";
    ct1 +=1;
   if (ct1 > 10 && lt3 == false) {ct1=0;  tm=1;k=1; jshalat=true; }   } 
  if (tm==2){
    if (t3==0) lt3=false;
    baris1="Rubah Tampilan";
    baris2 ="Jam + Tanggal";
    ct1 +=1;
   if (ct1 > 10 && lt3 == false) {ct1=0;  tm=1; k=1; jshalat=false; }   } } 

  
  if(b1!= baris1 || b2!=baris2 ) {
  b1= baris1 ; b2=baris2 ;
    lcd.clear() ;
  lcd.setCursor(0,0);
  lcd.print(b1);
  lcd.setCursor(0,1);
  lcd.print(b2);
  }


  if (hk==0) hari="Minggu" ;
  if (hk==1) hari="Senin" ;
  if (hk==2) hari="Selasa" ;
  if (hk==3) hari="Rabu" ;
  if (hk==4) hari="Kamis" ;
  if (hk==5) hari="Jum'at" ;
  if (hk==6) hari="Saptu" ;
 // end loop

}
byte bcdToDec(byte val)  {
// Convert binary coded decimal to normal decimal numbers
  return ( (val/16*10) + (val%16) );
}

byte decToBcd(byte val){
// Convert normal decimal numbers to binary coded decimal
  return ( (val/10*16) + (val%10) );
}

------------------------------------------------------------------------------------------


Gambar di atas adalah tampilan dari layar LCD ketika alat bekerja. JIka program yang kita buat sudah di Uploud maka alat akan bekerja pada posisi jalan dengan tampilan Jam yang di lengakapi jadwal Shalat. Karen Layar LCD hanya memuat sedikit karakter maka tampilan di atur agar menampilkan Jam, Tanggal, dan Jadwal Shalat secara bergantian. Coba lihat gambar dia atas. Tampilan Jam akan terus ada pada baris pertama Layar LCD, sedangkan untuk baris kedua akan diisi dengan tanggal dan jadwal shalat. jika kita ingin megubahnya maka tinggal tekan tombol atau saklar nomor 2 maka akan beralih mode menampilkan jam dan tanggal saja dan jika kita menekan tombol atau saklar nomor 3 maka alat akan kembali ke mode menampilkan jam, tanggal dan jadwal Shalat. 


Link Untuk kembali ke Halaman Praktek membuat Jadwal Shalat Abadi dengan Arduino Sesi 1




6 komentar:

  1. mas, mau tanya, kok setelah di set jamnya tidak berubah ya? jamnya menunjukkan pukul 45.165.165 dan tanggalnya 165-165-20165 mohon bantuannya ya..

    BalasHapus
    Balasan
    1. atau perlu di setting RTCnya dulu? kebetulan saya pake 3231, dan sudah saya sesuaikan di kodingnya terimakasih

      Hapus
    2. rtc 1337 mempunyai perbedaan dengan 3231. 1337 menampung data jam ,menit detik dll. masing masing dalam 1 variabel. untuk latihan di atas memang di tujukan untuk rtc 1337. sedangkan 3231 memiliki cara yg berbeda

      Hapus
    3. sebagai gambaran untuk berlatih 3231 begini saja. coba dulu program dasarnya. menampilkan jam dahulu. bagaimana merubahnya .nah baru kemudian di kembangkan untuk jadwal shalat. coba terlebih dahulu latihan dasar nya di link http://sakukurataa.blogspot.co.id/2017/04/arduino-dan-modul-ds-3231.html

      Hapus
    4. ooh oke deh saya coba ganti rtcnya, terimakasih

      Hapus
  2. Terima kasih dengan source codenya, Bagaimana kalau programnya ditambah dengan pengontrol Lampu Otomasis, Jika waktu terbit lampu akan padam dan jika Magrib lampu menyala.

    BalasHapus