Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <Wire.h>
- #include <TimeLib.h>
- #include <PrayerTimes.h>
- #include "RTClib.h"
- #include <LiquidCrystal_I2C.h>
- int timeAfterAthan = 1; // min
- int timeAfterSalat = 1; // min
- int testHour = 19;
- int testMin = 39;
- int fh, fm;
- int dh, dm;
- int ah, am;
- int mh, mm;
- int ih, im;
- int flag = 0;
- int newMin = 0;
- #define inRelay 6
- #define outRelay 7
- RTC_DS3231 rtc;
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- char daysOfTheWeek[7][12] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
- double times[sizeof(TimeName) / sizeof(char*)];
- void setup() {
- Serial.begin(57600);
- lcd.init();
- lcd.backlight();
- pinMode(inRelay, OUTPUT);
- pinMode(outRelay, OUTPUT);
- digitalWrite(inRelay, HIGH);
- digitalWrite(outRelay, HIGH);
- if (! rtc.begin()) {
- Serial.println("Couldn't find RTC");
- Serial.flush();
- while (1) delay(10);
- }
- if (rtc.lostPower()) {
- Serial.println("RTC lost power, let's set the time!");
- rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
- }
- }
- void loop() {
- DateTime now = rtc.now();
- int dst = 1;
- set_calc_method(Makkah);
- set_asr_method(Shafii);
- set_high_lats_adjust_method(AngleBased);
- set_fajr_angle(18.5);
- set_isha_angle(15);
- //JEDDAH MODIFIED BY DR JABER
- float latitude = 21.588657;
- float longitude = 39.219734;
- get_prayer_times(now.year(), now.month(), now.day(), latitude, longitude, 3, times);
- get_float_time_parts(times[0], fh, fm);
- get_float_time_parts(times[2], dh, dm);
- get_float_time_parts(times[3], ah, am);
- get_float_time_parts(times[5], mh, mm);
- get_float_time_parts(times[6], ih, im);
- im = im * 10;
- for (int i = 0; i < sizeof(times) / sizeof(double); i++) {
- //char tmp[10];
- int hourss, minutess;
- get_float_time_parts(times[i], hourss, minutess);
- Serial.print(i);
- Serial.print(" \t ");
- Serial.print(TimeName[i]);
- //Serial.print(" \t\t ");
- //Serial.print(times[i]);
- Serial.print(" \t\t");
- Serial.print(hourss);
- Serial.print(":");
- Serial.print(minutess);
- Serial.println();
- }
- Serial.print(now.year(), DEC);
- Serial.print('/');
- Serial.print(now.month(), DEC);
- Serial.print('/');
- Serial.print(now.day(), DEC);
- Serial.print(" (");
- Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
- Serial.print(") ");
- Serial.print(now.hour(), DEC);
- Serial.print(':');
- Serial.print(now.minute(), DEC);
- Serial.print(':');
- Serial.print(now.second(), DEC);
- Serial.println();
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print(now.hour());
- if (now.minute() < 10) {
- lcd.print(":0");
- }
- else {
- lcd.print(":");
- }
- lcd.print(now.minute());
- lcd.print(" ");
- lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
- lcd.print(" ");
- //Prayer Time if statments
- //*********************************************************************************
- ////////////////////////////////////////////////////////////////////
- /*
- if (now.hour() <= fh) {
- lcd.print(fh);
- lcd.print(":");
- lcd.print(fm);
- if (now.hour() == fh && now.minute() == fm) {
- lcd.setCursor(10, 1);
- lcd.print("OUT");
- //turn ON out Relay
- digitalWrite(inRelay, HIGH);
- digitalWrite(outRelay, LOW);
- }
- if (now.hour() == fh && now.minute() == fm + timeAfterAthan) {
- lcd.setCursor(10, 1);
- lcd.print("IN ");
- //turn ON in Relay
- digitalWrite(inRelay, LOW);
- digitalWrite(outRelay, HIGH);
- flag = 1;
- }
- }
- ////////////////////////////////////////////////////////////////////
- //*********************************************************************************
- ////////////////////////////////////////////////////////////////////
- else if (now.hour() <= dh) {
- lcd.print(dh);
- lcd.print(":");
- lcd.print(dm);
- if (now.hour() == dh && now.minute() == dm) {
- lcd.setCursor(10, 1);
- lcd.print("OUT");
- //turn ON out Relay
- digitalWrite(inRelay, HIGH);
- digitalWrite(outRelay, LOW);
- }
- if (now.hour() == dh && now.minute() == dm + timeAfterAthan) {
- lcd.setCursor(10, 1);
- lcd.print("IN ");
- //turn ON in Relay
- digitalWrite(inRelay, LOW);
- digitalWrite(outRelay, HIGH);
- flag = 1;
- }
- }
- ////////////////////////////////////////////////////////////////////
- //*********************************************************************************
- ////////////////////////////////////////////////////////////////////
- else if (now.hour() <= ah) {
- lcd.print(ah);
- lcd.print(":");
- lcd.print(am);
- if (now.hour() == ah && now.minute() == am) {
- lcd.setCursor(10, 1);
- lcd.print("OUT");
- //turn ON out Relay
- digitalWrite(inRelay, LOW);
- digitalWrite(outRelay, HIGH);
- }
- if (now.hour() == ah && now.minute() == am + timeAfterAthan) {
- lcd.setCursor(10, 1);
- lcd.print("IN ");
- //turn ON in Relay
- digitalWrite(inRelay, LOW);
- digitalWrite(outRelay, HIGH);
- flag = 1;
- }
- }
- ////////////////////////////////////////////////////////////////////
- //*********************************************************************************
- ////////////////////////////////////////////////////////////////////
- else if (now.hour() <= mh) {
- lcd.print(mh);
- lcd.print(":");
- lcd.print(mm);
- if (now.hour() == mh && now.minute() == mm) {
- lcd.setCursor(10, 1);
- lcd.print("OUT");
- //turn ON out Relay
- digitalWrite(inRelay, HIGH);
- digitalWrite(outRelay, LOW);
- }
- if (now.hour() == mh && now.minute() == mm + timeAfterAthan) {
- lcd.setCursor(10, 1);
- lcd.print("IN ");
- //turn ON in Relay
- digitalWrite(inRelay, LOW);
- digitalWrite(outRelay, HIGH);
- flag = 1;
- }
- }
- */
- ////////////////////////////////////////////////////////////////////
- //*********************************************************************************
- ////////////////////////////////////////////////////////////////////
- /*
- else if (now.hour() <= ih) {
- lcd.print(ih);
- lcd.print(":");
- lcd.print(im);
- if (now.hour() == ih && now.minute() == im) {
- lcd.setCursor(10, 1);
- lcd.print("OUT");
- //turn ON out Relay
- digitalWrite(inRelay, HIGH);
- digitalWrite(outRelay, LOW);
- }
- if (now.hour() == ih && now.minute() == im + timeAfterAthan) {
- lcd.setCursor(10, 1);
- lcd.print("IN ");
- //turn ON in Relay
- digitalWrite(inRelay, LOW);
- digitalWrite(outRelay, HIGH);
- flag = 1;
- }
- }
- */
- ////////////////////////////////////////////////////////////////////
- if (now.hour() <= testHour) {
- lcd.print(ih);
- lcd.print(":");
- lcd.print(im);
- if (now.hour() == testHour && now.minute() == testMin) {
- lcd.setCursor(10, 1);
- lcd.print("OUT");
- //turn ON out Relay
- digitalWrite(inRelay, HIGH);
- digitalWrite(outRelay, LOW);
- }
- if (now.hour() == testHour && now.minute() == testMin + timeAfterAthan) {
- lcd.setCursor(10, 1);
- lcd.print("IN ");
- //turn ON in Relay
- digitalWrite(inRelay, LOW);
- digitalWrite(outRelay, HIGH);
- flag = 1;
- }
- }
- //*********************************************************************************
- lcd.setCursor(0, 1);
- lcd.print(now.day());
- lcd.print("/");
- lcd.print(now.month());
- lcd.print("/");
- lcd.print(now.year());
- lcd.print(" ");
- if (flag == 1) {
- newMin = newMin + 10;
- if (newMin >= timeAfterSalat * 60) { // 600 = 10 min
- lcd.setCursor(10, 1);
- lcd.print(" ");
- digitalWrite(inRelay, HIGH);
- digitalWrite(outRelay, HIGH);
- flag = 0;
- }
- }
- delay(10000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement