SMK Binawiyata Sragen

  • This is default featured slide 1 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

  • This is default featured slide 2 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

  • This is default featured slide 3 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

  • This is default featured slide 4 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

  • This is default featured slide 5 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by Lasantha Bandara - Premiumbloggertemplates.com.

Membuat JWS ( Jadwal Waktu Sholat ) 1 Panel P10 dengan Arduino dilengkapi dpt diseting dng Aplikasi Android

Bahan yang di perlukan :
  1. Arduino UNO
  2. 1 Panel LED P10
  3. Bluetooth HC-05 atau HC-06
  4. RTC DS3231
  5. Buzzer Active
  6. Konverter Arduino ke DMD
  7. Charge HP 5V untuk power JWS
  8. Kabel Jumper secukupnya
  9. Kabel USB
Peralatan yang di perlukan 
  1. Komputer atau Laptop yang sdh terintal Arduino IDE 1.8.5
  2. Sumber Listrik
Gambar :
Source Code :
Terdiri dari 6 File 
  1. File Utama
  2. File Perhitungan Waktu Sholat
  3. File gambar desai Tampilan
  4. File Parameter
  5. File Penamaan ID
  6. File Tampilan Puasa
File Utama :
//**************************************************************************************/
#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;
                  }  
              }
          }
      }
  }

File Perhitungan Waktu Sholat :
//------------------------------------------
// 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); 
}

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 :
void check_puasa()
  {
    // hitung tanggal besok
    hijir_date tmrH = toHijri(now.year(),now.month(),now.day(),1); 
    ty_puasa = 0;
    // cek hari dilarang puasa
    if (  ((tmrH.hM == 12)  and   (tmrH.hD == 10)) or   // Idul Adha
          ((tmrH.hM == 12)  and   (tmrH.hD == 11)) or   // Hari Tarsik 1
          ((tmrH.hM == 12)  and   (tmrH.hD == 12)) or   // Hari Tarsik 2
          ((tmrH.hM == 12)  and   (tmrH.hD == 13)) or   // Hari Tarsik 3
          ((tmrH.hM == 10)  and   (tmrH.hD ==  1)) or   // Idul Fitri
          ((tmrH.hM ==  8)  and   (tmrH.hD == 29)) or   // Akhir bulan Sya'ban
          ((tmrH.hM ==  8)  and   (tmrH.hD == 30)))
        {
          ty_puasa = 0;
        }
    else 
        {
          if ((tmrH.hM == 10) and (tmrH.hD > 2))  // Bulan Syawal --> Puasa 6 Hari Sawal
            {
              ty_puasa = 1;  
              hd_puasa = 2;
            }
          if ((tmrH.hM == 8) and (tmrH.hD >= 1))  // Perbanyak puasa sunnah bulan Sya'ban
            {
              ty_puasa = 2;
              hd_puasa = 3;
            }  
        if(daynow== 1)  // Jika sekarang Minggu --> besok puasa Senin
            {
              ty_puasa = 3;
              hd_puasa = 1;
            }
        if(daynow== 4)  // Jika sekarang Rabu --> besok puasa Kamis
            {
              ty_puasa = 4;
              hd_puasa = 1;
            }
          if(tmrH.hD == 13 or tmrH.hD == 14 or tmrH.hD == 15)   // Puasa Tengah Bulan tgl 13,14,15
            {
              ty_puasa = 5;
              hd_puasa = 1;
            }
          if ((tmrH.hM == 12) and (tmrH.hD == 9))  // 9 Dzulhijah --> Puasa Arofah
            {
              ty_puasa = 6;
              hd_puasa = 1;
            }
          if ((tmrH.hM == 12) and (tmrH.hD < 9))  // 9 hari pertama Dzulhijah --> Puasa Awal Dzulhijah
            {
              ty_puasa = 7;
              hd_puasa = 1;
            }
          if ((tmrH.hM == 1) and (tmrH.hD == 9))  // 9 Muharram --> Puasa Arofah
            {
              ty_puasa = 8;
              hd_puasa = 1;
            }
          if ((tmrH.hM == 1) and (tmrH.hD == 10))  // 10 Muharram --> Puasa Asura
            {
              ty_puasa = 9;
              hd_puasa = 1;
            }
          if (tmrH.hM == 9)  // Puasa Ramadhan
            {
              ty_puasa = 10;
              hd_puasa = 4;
            }
        }
  }

Share:

Live 3 Maret 2018 - Mempelajari Bacaan Sholat - Ustadz Adi Hidayat Lc.MA

Share:

Arduino & Audio

Dalam artikel ini kita akan bermain dengan suara bersama Arduino mulai dari menggunakan fungsi tone() untuk membangkitkan nada hingga proyek kompleks yang sanggup membuat Arduino memainkan musik polyphonic dan mengucapkan kalimat yang diberikan dari masukan berupa teks. Untuk itu artikel ini akan dibagi menjadi beberapa bagian bersambung.
Mari kita mulai dari yang paling sederhana… membangkitkan nada dengan frekuensi tertentu.
Sebelum memulai dengan kode program, mari kita buat perangkat kerasnya terlebih dahulu. Yang perlu kita persiapkan:
  • Arduino Uno
  • Speaker 8 ohm
  • Resistor 100 ohm
  • Papan Rancang  Purnarupa (Prototype Design Board), atau dikenal dengan istilah Breadboard
Hubungkan komponen-komponen elektronika yang sudah Anda siapkan seperti ilustrasi di bawah ini (credit: gambar dibuat dengan Fritzing dan retouch menggunakan Adobe Photoshop):
Resistor yang dihubungkan secara seri ini berguna untuk membatasi penggunaan arus.
Dalam banyak tutorial tentang topik ini, penggunaan komponen tambahan seperti resistor di atas jarang dibahas, kita cuma diarahkan untuk merangkainya seperti itu tanpa mengerti alasannya. Dalam seri artikel ini, kita akan mempelajari sedikit lebih jauh alasan dibalik penggunaan suatu komponen.
Resistor ini disebut sebagai resistor pembatas arus (current limiting resistor). Sesuai petunjuk pada manual penggunaan Arduino, jumlah arus yang boleh ditarik dari satu pin hanyalah sebesar maksimum 50 mA. Sesuai hukum Ohm, dengan tegangan operasional sebesar 5V (setara 5000 mV) diperlukan hambatan beban (load resistance) sebesar  5000 mV / 50 mA = 100 Ω. Karena speaker yang kita gunakan mempunyai impedansi (impedance, nilai hambatan) sebesar 8 Ω, secara teori kita bisa menggunakan resistor 92 Ω dalam rangkaian ini. Walaupun demikian kita memilih untuk menggunakan resistor 100 Ω karena dua alasan: (1) 50 mA adalah batasan maksimum, sebaiknya kita jangan terlalu memaksakan nilai maksimum ini, dan (2) resistor 100Ω banyak tersedia dan mudah didapat dibanding resistor 92 Ω.
Setelah selesai menghubungkan komponen-komponen tersebut, mari kita mulai membuat programnya. Bukalah aplikasi Arduino IDE, lalu masukkan kode berikut ini:
void setup() {
  pinMode( 8, OUTPUT );
  pinMode( 13, OUTPUT );
}

void loop() {
  // matikan LED
  digitalWrite( 13, LOW );
  // mainkan nada di pin#8 dg. frekuensi 261Hz selama 500 ms
  tone( 8, 261 );
  delay( 500 );
  // nyalakan LED
  digitalWrite( 13, HIGH );
  // mainkan nada di pin#8 dg. frekuensi 392Hz selama 500 ms
  tone( 8, 392 );
  delay( 500 );
}

Sambungkan Arduino dengan komputer melalui kabel USB, lalu unggah (upload) kode tersebut ke Arduino. Caranya ada 3, silakan pilih salah satu: (1) tekan tombol Upload (tombol berbentuk lingkaran dengan tanda panah menunjuk ke kanan), (2) melalui menu File → Upload, atau (3) tekan kombinasi tombol Ctrl+U.
Bila kode berhasil diunggah, akan terdengar suara seperti sirine dimana dua buah nada dengan pitch berbeda (yang satu lebih rendah dibanding yang lainnya) akan dimainkan bergantian masing-masing selama setengah detik (500 milliseconds).
Dengan menelaah kode di atas, dengan jelas terlihat bahwa untuk membunyikan nada dengan frekuensi dan durasi tertentu di Arduino sangatlah mudah, yaitu dengan menggunakan fungsi tone().
Fungsi tone() ini menerima 2 atau 3 parameter sebagai masukannya, dengan format sbb.:
tonepinfrekuensidurasi );
Parameter pertama adalah nomor pin yang digunakan untuk keluaran ke speaker. Parameter kedua adalah frekuensi yang ingin dibunyikan dalam Hz (Hertz, getaran per detik). Parameter ketiga adalah durasi dalam milidetik, menyatakan berapa lama nada tersebut akan dibunyikan. Parameter durasi bersifat opsional, artinya boleh tidak diisikan. Bila tidak diisikan, maka nada tersebut akan dibunyikan tanpa batas waktu, untuk mematikannya dengan memanggil fungsi noTonepin ).
Yang perlu diperhatikan saat parameter durasi dinyatakan, fungsi ini akan kembali sesegera mungkin tanpa menunggu durasi tersebut terlewati (nada selesai dimainkan).
Pada kecepatan 16 Hz (Arduino Uno bekerja di kecepatan ini), frekuensi yang dapat dimainkan berkisar antara 31 Hz hingga 8 MHz. Sebagai catatan, frekuensi yang dapat didengar oleh telinga manusia berkisar antara 20 hingga 20 kHz.
Pada contoh kode di ditambahkan kode untuk membuat LED berkelap-kelip selaras pitch nada yang dimainkan, mirip dengan lampu sirine polisi.
Untuk lebih puas bereksperimen dengan fungsi tone() ini, cobalah unggah kode berikut ini…
void setup() {
  Serial.begin( 9600 );
  pinMode( 8, OUTPUT ); 
}
word f = 0;
word d = 0;
boolean koma = false;
void loop() {
  if( Serial.available() ) {
    char c = Serial.read();
    if( c >= '0' && c <= '9' ) {
      if( koma ) d = ( d * 10 ) + ( c - 48 );
      else f = ( f * 10 ) + ( c - 48 );
    }
    else if( c == ',' ) {
      koma = true;
      d = 0;
    }
    else if( c == 10 ) { 
      if( f ) {
        if( d ) tone( 8, f, d );
        else tone( 8, f );
      }
      else noTone( 8 );
      f = 0;
      koma = false;
    }
  }
}

Setelah kode termuat ke Arduino, buka jendela Serial Monitor dengan menekan tombol di bagian sebelah kanan pada baris tombol Arduino IDE (bergambar seperti kaca pembesar dengan dua titik berderet di sampingnya). Pada kolom masukan di Serial Monitor, masukkan angka antara 31 sampai 20.000 lalu tekan ENTER. Arduino akan memainkan nada dengan frekuensi yang Anda masukkan. Menekan ENTER tanpa mengisikan angka akan menghentikan bunyi. Untuk menyetel durasi, masukkan nilai durasi dalam milidetik setelah nilai frekuensi dengan dipisahkan tanda koma.
Catatan: pastikan setelan baudrate pada Serial Monitor (kotak pilihan di sudut kanan bawah) pada kecepatan 9600 baud dan modus masukan Newline (pada kotak pilihan di sebelah kiri pilihan baudrate) sudah terpilih.
Simpanlah sketch ini dengan nama ArduinoAudio (otomatis akan disimpan dalam file ArduinoAudio.ino dalam subfolder ArduinoAudio) dengan mengeksekusi menu File Save As…
Di bagian berikutnya kita akan bermain dengan nada musik (musical notes) dengan membuat simulasi piano. Lanjutkan ke “Arduino & Audio: Musical Notes”…
Share:

Membuat Radio FM Arduino Uno dengan Display P10 LED Matrix

  1. Alat dan Bahan :
  • LED matrix P10 3 Block
  • Tumer FM TEA5767
  • Board Arduino Uno
  • Konverter socket DMD P10
  1. Gambar
  • LED  Matrix panel P10 


  • FM Tuner TEA5657


  • Board Arduino Uno





C. Source Kode

#include
#include
#include
#include
#include
#include
#include
#include
// Init radio object
TEA5767N radio = TEA5767N();

// Buttons codes
#define btnRIGHT    0
#define btnUP       1
#define btnDOWN     2
#define btnLEFT     3
#define btnSELECT   4
#define btnNONE     5

// Delay between clock transitions
#define DELAY_VOLUME_TRANSITION 90

// Definition of the 3-dimension array
#define MENU_DEPTH 3
#define MENU_LINES 8
#define MENU_TEXT  16

// Arduino pin for backlight intensity control
#define BACKLIGHT_PIN 3

// Arduino pins connected to digital potentiometers
// for volume control
#define UPDOWN_PIN    11
#define INC_PIN       12

// Predefined stations array
float defaultStations[16] = {88.0, 88.8,94.7,91.1,  98.4, 98.8, 101.5, 101.7,  102.2, 104.5, 106.0, 107.7,  101.4, 102.2, 103.4, 88.8};
// Initialized station arrays
float stations[16] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
byte stationIndex = 0;
byte applicationState = 0;
byte selectedMenuItem = 0;
float selectedStation;
boolean buttonWasReleased = true;
int lcd_key = 0;

// Menu labels
char menu[MENU_DEPTH][MENU_LINES][MENU_TEXT] = {
   {{" Diam"}, {" Pencarian"}, {" Cari Halus"}, {" Simpan Station"}, {" Configuration"}, {" Stand by"}, {" Load deflt stn"}, {" Exit"}},
   {{" Search level"}, {" Backlit inten."}, {" Exit"}},
   {{" Low"}, {" Medium"}, {" High"}, {"Exit"}}
  };

// Level required to search
byte searchLevel;
// Intensity of LCD backlight.
// Varies from 0 to 255
int backlightIntensity;

// Copy the predefined stations into the
// array used by the application
void loadDefaultStations() {
  for (int i=0 ; i < 16 ; i++) {
     stations[i] = defaultStations[i];
  }
}
// Convert the analog values read from Arduino pin A0
// into one of the five commands plus the NONE button 
int read_LCD_buttons() {
  int adc_key_in = analogRead(0);
  if (adc_key_in > 1000) return btnNONE; 
  if (adc_key_in < 50) return btnRIGHT; 
  if (adc_key_in < 195) return btnUP; 
  if (adc_key_in < 380) return btnDOWN; 
  if (adc_key_in < 555) return btnLEFT; 
  if (adc_key_in < 790) return btnSELECT; 
  return btnNONE;
}

byte findSelectedStationIndex(float station) {
  for (int i = 0 ; i < 16 ; i++) {
    if (stations[i] == station) {
      return i;
    }
  }
  return 0;
}

// Load the station stored in the EEPROM static memory
void loadStation() {
  byte intStation, floatStation;
  float station;
  
  intStation = EEPROM.read(0);
  floatStation = EEPROM.read(1);
  
  if (intStation != 0xFF) {
    station = (intStation * 1.0) +  (floatStation * .1);
    radio.selectFrequency(station);
    printSelectedFrequency(radio.readFrequencyInMHz());
    stationIndex = findSelectedStationIndex(station);
  } else {
    radio.selectFrequency(stations[stationIndex]);
  }
}

// Load the search level stored in the EEPROM static memory
void loadSearchLevel() {
  searchLevel = EEPROM.read(2);
  if (searchLevel == 0xFF) {
    searchLevel = MID_STOP_LEVEL;
  }
  switch(searchLevel) {
    case LOW_STOP_LEVEL: {
      radio.setSearchLowStopLevel();
      break;
    }
    case MID_STOP_LEVEL: {
      radio.setSearchMidStopLevel();
      break; 
    }
    case HIGH_STOP_LEVEL: {
      radio.setSearchHighStopLevel();
      break; 
    }
  }
}

// Load the backlight intensity stored in the EEPROM static memory
void loadBacklightIntensity() {
  backlightIntensity = EEPROM.read(3);
  analogWrite(BACKLIGHT_PIN, (byte) backlightIntensity);
}

void setupVolume() {
  // Lowest volume
  digitalWrite(UPDOWN_PIN, LOW);
  for (int i = 0 ; i < 100 ; i++) {
    digitalWrite(INC_PIN, LOW);
    delay(1);
    digitalWrite(INC_PIN, HIGH);
    delay(1);
  }
  // Pleasant level
  digitalWrite(UPDOWN_PIN, HIGH);
  for (int i = 0 ; i < 15 ; i++) {
    digitalWrite(INC_PIN, LOW);
    delay(1);
    digitalWrite(INC_PIN, HIGH);
    delay(1);
  }
}

void loadConfiguration() {
  radio.mute();
  loadDefaultStations();
  loadStation();
  loadSearchLevel();
  loadBacklightIntensity();
  setupVolume();
  radio.turnTheSoundBackOn();
}

void saveStation(float station) {
  float aux;
  byte byteValue;
  
  byteValue = (byte) floor(station);
  EEPROM.write(0, byteValue);
  aux = station - floor(station);
  aux *= 10.0;
  if (aux > 5.0) {
    byteValue = byte(aux);
    if ((((float)byteValue) - aux) > 0.1) {
      byteValue--;
    } else if ((aux - ((float)byteValue)) > 0.1) {
      byteValue++;
    }
  } else {
    byteValue = (int) ceil(aux);
  }
  EEPROM.write(1, byteValue);
}

void saveSearchLevel(byte searchLevel) {
  EEPROM.write(2, searchLevel);
}

DMD dmd(3, 1);

void ScanDMD()
{
  dmd.scanDisplayBySPI();
}
//================================================
void setup(){
  Wire.begin();
  Timer1.initialize( 500 );
  Timer1.attachInterrupt( ScanDMD );
  
  pinMode(BACKLIGHT_PIN, OUTPUT);  
  pinMode(UPDOWN_PIN, OUTPUT);
  pinMode(INC_PIN, OUTPUT);
  
  digitalWrite(UPDOWN_PIN, HIGH);
  digitalWrite(INC_PIN, HIGH);
  analogWrite(BACKLIGHT_PIN, 255);  
  
  dmd.selectFont(SystemFont5x7);
  dmd.drawString(1,0,"TEA5767 FM Radio",16,0);  
  dmd.drawString(1,9,"By Suparno, M.Pd",16,0); 
  delay(3000);
  dmd.clearScreen(true);
  dmd.drawString(36,0,"MHz",3,0);  
  // Loads configuration
  loadConfiguration();
  radio.setSoftMuteOn();  
  radio.setHighCutControlOn();
}

void printSelectedFrequency(float frequency) {
  printSelectedFrequency(frequency, 0, 0);
}

void printSelectedFrequency(float frequency, byte col, byte row) {
  char str_freq[5];
  dtostrf(frequency, 1, 1, str_freq);  
  dmd.drawString(0,0,str_freq,5,0);  
}

void printMuteStatus() {
  if (radio.isMuted()) {   
    dmd.drawString(84,9,"Mu",2,0);
  } else {
    dmd.drawString(84,9,"Re",2,0);   
  }
}

void printStereoStatus() { 
  //dmd.clearScreen(true);
  if (radio.isStereo()) {   
    dmd.drawString(60,0,"Stereo",6,0);
  } else {    
    dmd.drawString(60,0,"Mono  ",6,0);
  }
}

void markSelectedMenuItem(char *firstLine, char *secondLine) { 
  dmd.drawString(90,1,firstLine,16,0);  
  dmd.drawString(90,9,secondLine,16,0);
}

void updateLevelIndicator() {
  byte x, y, sl;
  char barGraph[17];
  
  sl = radio.getSignalLevel();
  for (x=0 ; x
    barGraph[x] = 255;
  }
  for (y=x ; y<16 div="" y="">
    barGraph[y] = 16;//32;
    barGraph[y] = '>'; 
  }
   
  dmd.drawString(0,9,barGraph,16,0);
  
}

void loop() { 
  lcd_key = read_LCD_buttons(); 
  
  if ((lcd_key != btnNONE) && radio.isStandBy() && buttonWasReleased) {
    buttonWasReleased = false;
    applicationState = 0;  
   
    radio.mute();
    radio.setStandByOff();    
    delay(150);
    radio.turnTheSoundBackOn();
    analogWrite(BACKLIGHT_PIN, (byte) backlightIntensity);  
    dmd.clearScreen(true);   
    dmd.drawString(0,0,"      MHz",16,0);   
    printSelectedFrequency(radio.readFrequencyInMHz());
  }  
  
  switch (lcd_key) {    
    case btnRIGHT: {     
      if (buttonWasReleased) {        
        buttonWasReleased = false;        
        switch (applicationState) {          
          case 0: {
            if ((stationIndex < 15) && (stations[stationIndex+1] != 0.0)) {
              stationIndex++;
            } else {
              stationIndex = 0;
            }           
            radio.mute();
            radio.selectFrequency(stations[stationIndex]);
            radio.turnTheSoundBackOn();            
            printSelectedFrequency(radio.readFrequencyInMHz());
            saveStation(stations[stationIndex]);
            break;
          }
          // Search ahead
          case 5: {
            byte isBandLimitReached = false;
            if (selectedMenuItem == 1) {
              radio.setSearchUp();
              isBandLimitReached = radio.searchNextMuting();
              if (isBandLimitReached) {
                radio.setSearchDown();
                isBandLimitReached = radio.searchNextMuting();
              }
              printSelectedFrequency(radio.readFrequencyInMHz(), 2, 0);
            }
            break; 
          }         
          case 6: {
            if (selectedStation < 108.0) {
              selectedStation += .1;
              radio.selectFrequency(selectedStation);
              printSelectedFrequency(selectedStation, 2, 0);
              saveStation(selectedStation);
            }
            break;
          }         
          case 7: {
            backlightIntensity += 10;
            if (backlightIntensity > 255) {
              backlightIntensity = 255;
            }           
            analogWrite(BACKLIGHT_PIN, (byte) backlightIntensity);
            EEPROM.write(3, (byte) backlightIntensity);
            break;
          }
        }
      }
      break;
    }    
    case btnLEFT: {
      if (buttonWasReleased) {
        buttonWasReleased = false;
        switch (applicationState) {
          // First screen, so change station
          case 0: {
            if (stationIndex > 0) {
              stationIndex--;
            } else {
              stationIndex = 15;
              while((stations[stationIndex] == 0.0) && (stationIndex > 0)) {
                stationIndex--;
              }
            }
            radio.mute();
            radio.selectFrequency(stations[stationIndex]);
            radio.turnTheSoundBackOn();
            printSelectedFrequency(radio.readFrequencyInMHz());
            saveStation(stations[stationIndex]);
            break;
          }
          // Search backwards
          case 5: {
            byte isBandLimitReached;
            if (selectedMenuItem == 1) {
              radio.setSearchDown();
              isBandLimitReached = radio.searchNextMuting();
              if (isBandLimitReached) {
                radio.setSearchUp();
                isBandLimitReached = radio.searchNextMuting();
              }
              printSelectedFrequency(radio.readFrequencyInMHz(), 2, 0);
            }
            break; 
          }
          // Decrement fine search station
          case 6: {
            if (selectedStation > 88.0) {
              selectedStation -= .1;
              radio.selectFrequency(selectedStation);
              printSelectedFrequency(selectedStation, 2, 0);
              saveStation(selectedStation);
            }
            break;
          }
          // Decrement backlight intensity
          case 7: {
            backlightIntensity -= 10;
            if (backlightIntensity < 0) {
              backlightIntensity = 0;
            }
            analogWrite(BACKLIGHT_PIN, (byte) backlightIntensity);
            EEPROM.write(3, (byte) backlightIntensity);
            break;
          }
        }
      }
      break;
    }
    case btnUP: {      
      if (buttonWasReleased || (applicationState == 0)) {
        buttonWasReleased = false;
        switch (applicationState) {
          //Volume UP
          case 0: {
            digitalWrite(UPDOWN_PIN, HIGH);
            digitalWrite(INC_PIN, LOW);
            delay(DELAY_VOLUME_TRANSITION);
            digitalWrite(INC_PIN, HIGH);
            delay(DELAY_VOLUME_TRANSITION);
            break;
          }
          // Menu navigation up
          case 1: {
            if (selectedMenuItem > 0) {
              selectedMenuItem--;
              
              if (selectedMenuItem != 3) {
               
                dmd.clearScreen(true);                
                dmd.drawString(0,0,menu[0][selectedMenuItem],16,0);               
                dmd.drawString(0,9,menu[0][selectedMenuItem+1],16,0);
              }
            }
            markSelectedMenuItem("<", " ");
            break;
          }         
          case 3: {
            if (selectedMenuItem > 0) {
              selectedMenuItem--;
              
              if (selectedMenuItem != 3) {
                dmd.clearScreen(true);                
                dmd.drawString(0,0,menu[1][selectedMenuItem],16,0);               
                dmd.drawString(0,9,menu[1][selectedMenuItem+1],16,0);
              }
            }
            markSelectedMenuItem("<", " ");
            break;
          }
          // Search level navigation up
          case 4: {
            if (selectedMenuItem > 0) {
              selectedMenuItem--;
              
              if (selectedMenuItem != 2) {
                dmd.clearScreen(true);               
                dmd.drawString(0,0,menu[2][selectedMenuItem],16,0);                
                dmd.drawString(0,9,menu[2][selectedMenuItem+1],16,0);
              }
            }
            markSelectedMenuItem("<", " ");
            break; 
          }
        }
      }
      break;
    }    
    case btnDOWN: {    
      if (buttonWasReleased || (applicationState == 0)) {
        buttonWasReleased = false;
        switch (applicationState) {
          //Volume DOWN
          case 0: {
            digitalWrite(UPDOWN_PIN, LOW);
            digitalWrite(INC_PIN, LOW);
            delay(DELAY_VOLUME_TRANSITION);
            digitalWrite(INC_PIN, HIGH);
            delay(DELAY_VOLUME_TRANSITION);
            break;
          }
          // Menu navigation down
          case 1: {
            if (selectedMenuItem < (MENU_LINES-1)) {
              selectedMenuItem++;
              
              if (selectedMenuItem != 1) {                
                dmd.clearScreen(true);                
                dmd.drawString(0,0,menu[0][selectedMenuItem-1],16,0);                
                dmd.drawString(0,9,menu[0][selectedMenuItem],16,0);
              }
            }
            markSelectedMenuItem(" ", "<");
            break;
          }         
          case 3:
            if (selectedMenuItem < 2) {
              selectedMenuItem++;
              
              if (selectedMenuItem != 1) {
                dmd.clearScreen(true);                
                dmd.drawString(0,0,menu[1][selectedMenuItem-1],16,0);               
                dmd.drawString(0,9,menu[1][selectedMenuItem],16,0);
              }
            }
            markSelectedMenuItem(" ", "<");
            break;
          // Search level navigation down
          case 4: {
            if (selectedMenuItem < 2) {
              selectedMenuItem++;
              if (selectedMenuItem != 1) {
                dmd.clearScreen(true);                
                dmd.drawString(0,0,menu[2][selectedMenuItem-1],16,0);               
                dmd.drawString(0,9,menu[2][selectedMenuItem],16,0);
              }
            }
            markSelectedMenuItem(" ", "<");
            break; 
          }
        }
      }
      break;
    }
    // Typically starts the menu or execute a command
    case btnSELECT: {
      if (buttonWasReleased) {
        buttonWasReleased = false;
        switch (applicationState) {          
          case 0: {
            applicationState = 1;
           // lcd.clear();
            dmd.clearScreen(true);
            dmd.drawString(0,0,menu[0][0],16,0);           
            dmd.drawString(0,9,menu[0][1],16,0);
            markSelectedMenuItem("<", " ");
            selectedMenuItem = 0;
            break;
          }          
          case 1: {
            switch(selectedMenuItem) {
              //Mute function
              case 0: {
                applicationState = 0;
                if (!radio.isMuted()) {
                  radio.mute();
                } else {
                  radio.turnTheSoundBackOn();
                }
                dmd.drawString(0,0, "      MHz",16,0);                
                dmd.drawString(0,9, "         ",16,0);
                printMuteStatus();
                
                // Starts station
                printSelectedFrequency(radio.readFrequencyInMHz());
                break; 
              }
              //Search
              case 1: {
                applicationState = 5;
                dmd.clearScreen(true);                
                 dmd.drawString(0,0, "<",1,0);                
                 dmd.drawString(90,0, ">",1,0);
                printSelectedFrequency(radio.readFrequencyInMHz(), 2, 0);
                break; 
              }
              //Fine search
              case 2: {
                applicationState = 6;
                 dmd.clearScreen(true);                
                dmd.drawString(0,0, "<<",2,0);               
                dmd.drawString(84,0, ">>",2,0);
                selectedStation = radio.readFrequencyInMHz();
                printSelectedFrequency(selectedStation, 2, 0);
                break; 
              }             
              case 3: {
                byte isBandLimitReached = 0;
                byte progress = 0;
                applicationState = 0;
                
                dmd.clearScreen(true);                
                dmd.drawString(0,0, "Searching ...",16,0);
                radio.mute();
                radio.selectFrequency(88.0);
                radio.setSearchUp();
                while(!isBandLimitReached && (progress < 16)) {
                  isBandLimitReached = radio.searchNext();
                  stations[progress] = radio.readFrequencyInMHz();                  
                  dmd.drawString(0,9, progress,16,0);                 
                  dmd.drawString(0,9,(char)255,16,0);
                  progress++;
                }
                radio.turnTheSoundBackOn();                
               
                dmd.drawString(0,0,"      MHz        ",16,0);              
                dmd.drawString(0,9,"                 ",16,0);
                // Starts station
                stationIndex = 0;
                saveStation(stations[stationIndex]);
                printSelectedFrequency(stations[stationIndex]);
                
                break;
              }
              //Configuration
              case 4: {
                applicationState = 3;
                dmd.clearScreen(true);               
                dmd.drawString(0,0,menu[1][0],16,0);               
                dmd.drawString(0,9,menu[1][1],16,0);
                markSelectedMenuItem("<", " ");
                selectedMenuItem = 0;
                break;
              }              
              case 5: {
                applicationState = 2;
                //lcd.clear();
                dmd.clearScreen(true);
                radio.setStandByOn();
                analogWrite(BACKLIGHT_PIN, 0);
                
                break; 
              }
              //Load default station
              case 6: {
                applicationState = 0;                
                dmd.drawString(0,0,"      MHz        ",16,0);               
                dmd.drawString(0,9,"                 ",16,0);
                // Starts station
                loadDefaultStations();
                
                radio.mute();
                radio.selectFrequency(stations[0]);
                radio.turnTheSoundBackOn();
                
                printSelectedFrequency(radio.readFrequencyInMHz());
                saveStation(stations[stationIndex]);
                break;
              }
              //Exit
              case 7: {
                applicationState = 0;               
                dmd.drawString(0,0,"      MHz        ",16,0);               
                dmd.drawString(0,9,"                 ",16,0);
                // Starts station
                printMuteStatus();
                
                // Starts station
                printSelectedFrequency(radio.readFrequencyInMHz());
                break;
              }
            }
            break;
          }
         
          case 3: {
            switch(selectedMenuItem) {              
              case 0: {
                applicationState = 4;
                //lcd.clear();
                dmd.clearScreen(true);
                if (searchLevel < 3) {                 
                  dmd.drawString(0,0,menu[2][0],16,0);                
                  dmd.drawString(0,9,menu[2][1],16,0);
                } else {                 
                  dmd.drawString(0,0,menu[2][1],16,0);                 
                  dmd.drawString(0,9,menu[2][2],16,0);
                }
                if (searchLevel == 1) {
                  markSelectedMenuItem("<", " ");
                } else {
                  markSelectedMenuItem(" ", "<");
                }
                selectedMenuItem = searchLevel - 1;
                break;
              }
              // Backlight intensity selected
              case 1: {
                applicationState = 7;
            
                
                dmd.clearScreen(true);                
                dmd.drawString(0,0,"Backlight int.",16,0);
                break;
              }
              // Exit
              case 2: {
                applicationState = 0;            
                
                dmd.drawString(0,0,"      MHz        ",16,0);               
                dmd.drawString(0,9,"                 ",16,0);
                printMuteStatus();
                
                // Starts station
                printSelectedFrequency(radio.readFrequencyInMHz());
                break; 
              }
            }
            break; 
          }
          // One of the levels selected
          case 4: {
            applicationState = 0;
            switch(selectedMenuItem+1) {
              case LOW_STOP_LEVEL: {
                radio.setSearchLowStopLevel();
                saveSearchLevel(LOW_STOP_LEVEL);
                break;
              }
              case MID_STOP_LEVEL: {
                radio.setSearchMidStopLevel();
                saveSearchLevel(MID_STOP_LEVEL);
                break; 
              }
              case HIGH_STOP_LEVEL: {
                radio.setSearchHighStopLevel();
                saveSearchLevel(HIGH_STOP_LEVEL);
                break; 
              }
            }            
                 dmd.drawString(0,0,"      MHz        ",16,0);
                 dmd.drawString(0,9,"                 ",16,0);
            printMuteStatus();
            
            // Starts station
            printSelectedFrequency(radio.readFrequencyInMHz());
            break; 
          }
          // Exit
          // Several states to exit from
          case 5: // Exit from Search
          case 6: // Exit from Fine search
          case 7: { // Exit from Backlight intensity
            applicationState = 0;
            
           
            dmd.clearScreen(true);            
            dmd.drawString(0,0,"       MHz       ",16,0);
            printMuteStatus();
            
            // Starts station
            printSelectedFrequency(radio.readFrequencyInMHz());
            break; 
          }
        }
      }
      break;
    }
    // The buttons were scanned and none were pressed
    case btnNONE: {
      if (!buttonWasReleased) {
        buttonWasReleased = true;
      }      
      switch (applicationState) {
        case 0: {         
          if (!radio.isStandBy()) {           
            printStereoStatus();
          }         
          updateLevelIndicator();
          break;
        }
        case 5: {         
          updateLevelIndicator(); 
          break;
        }
      }
      break;
    }
  } 
  delay(10);
}
Share:

Jadwal Waktu Sholat

TIME WIB

TV EDUKASI LIVE

Popular Posts

Recent Posts

Pages