WeMOS: D1 R1 mini Prayer Time Indonesia

From OnnoWiki
Jump to navigation Jump to search
/*
 * Calculate Prayer Time
 */

int Y = 2023;
int M = 4;
int D = 4;
int H = 16;
int m = 25;
int s = 0;
int Z = 7;
// # define PI           = 3.14159265359;
float LAT                = -6.16858549901122;
float LONG               = 106.865053367193;
float FAJR_ANGLE         = 20;
float ISHA_ANGLE         = 18; 
float SF                 = 1;      // Imam Safii
float DESCEND_CORRECTION = 2/60;
 
float FAJR;
float SUNRISE;
float ZUHR;
float ASR;
float MAGHRIB;
float ISHA;

void setup() {
  Serial.begin(9600);
  delay(500);
  calcPrayerTime();
  Serial.println( "\n" );
  PrintFloatToHour( FAJR );
  PrintFloatToHour( SUNRISE );
  PrintFloatToHour( ZUHR );
  PrintFloatToHour( ASR );
  PrintFloatToHour( MAGHRIB );
  PrintFloatToHour( ISHA );
}

void loop() {
  // put your main code here, to run repeatedly:
}
 

void PrintFloatToHour( float prayertime ) {
  int hh;
  int mm; 

  hh = int( prayertime );
  mm = int( ( prayertime - hh )*60 );
  if( hh<9 ) Serial.print( String( "0" ) );
  Serial.print( String(hh) + ":" );
  if( mm<9 ) Serial.print( String( "0" ) );
  Serial.println( String(mm) ); 
}
void calcPrayerTime() {
  int A = Y/100 ;
  int B = 2 + int(A/4) - A;
  float JD = 1720994.5 + int(365.25*Y) + int(30.6001*(M + 1)) + B + D + ((H*3600 + m*60 + s) / 86400) - (Z / 24 );
  float T = 2 * PI * (JD - 2451545) / 365.25;
  float DELTA = 0.37877 + 23.264 * sin( (57.297*T - 79.547) * PI/180 ) + 0.3812 * sin( (2*57.297*T - 82.682) * PI/180 ) + 0.17132 * sin( (3*57.297*T - 59.722) * PI/180 );
  
  float U = (JD - 2451545) / 36525;
  float L0 = 280.46607 + 36000.7698*U;
  float ET1000 = -(1789 + 237*U) * sin(L0 * PI/180) - (7146 - 62*U) * cos(L0 * PI/180) + (9934 - 14*U) * sin(2*L0 * PI/180) - (29 + 5*U) * cos(2*L0 * PI/180) + (74 + 10*U) * sin(3*L0 * PI/180) + (320 - 4*U) * cos(3*L0 * PI/180) - 212*sin(4*L0 * PI/180);
  float ET = ET1000 / 1000;
  float TT = 12 + Z - (LONG / 15) - (ET / 60);

  float SA_FAJR = -(FAJR_ANGLE);
  float SA_MAGHRIB = -0.8333 - (0.0347 * sqrt(H));
  float SA_SUNRISE = SA_MAGHRIB;
  // acot(A) = atan(1/A)
  // float SA_ASR = acot(SF + tan(abs(DELTA-LAT)*PI/180))*180/PI;
  float SA_ASR = atan(1/(SF + tan(abs(DELTA-LAT)*PI/180)))*180/PI;
  float SA_ISHA = -(ISHA_ANGLE);
   
  float COSHA_FAJR = (sin(SA_FAJR *PI/180) - sin(LAT*PI/180) * sin(DELTA*PI/180)) / (cos(LAT*PI/180) * cos(DELTA*PI/180));
  float COSHA_MAGHRIB = (sin(SA_SUNRISE*PI/180) - sin(LAT*PI/180) * sin(DELTA*PI/180)) / (cos(LAT*PI/180) * cos(DELTA*PI/180));
  float COSHA_SUNRISE = COSHA_MAGHRIB;
  float COSHA_ASR = (sin(SA_ASR*PI/180) - sin(LAT*PI/180) * sin(DELTA*PI/180)) / (cos(LAT*PI/180) * cos(DELTA*PI/180));
  float COSHA_ISHA = (sin(SA_ISHA*PI/180) - sin(LAT*PI/180) * sin(DELTA*PI/180)) / (cos(LAT*PI/180) * cos(DELTA*PI/180));
 
  float HA_FAJR = acos(COSHA_FAJR)*180/PI;
  float HA_MAGHRIB = acos(COSHA_SUNRISE)*180/PI;
  float HA_SUNRISE = HA_MAGHRIB;
  float HA_ASR = acos(COSHA_ASR)*180/PI;
  float HA_ISHA = acos(COSHA_ISHA)*180/PI;
  
  FAJR = TT - HA_FAJR / 15;
  SUNRISE = TT - HA_SUNRISE / 15;
  ZUHR = TT + DESCEND_CORRECTION;
  ASR = TT + HA_ASR / 15;
  MAGHRIB = TT + HA_MAGHRIB / 15;
  ISHA = TT + HA_ISHA / 15;  
}