Advertisement
safwan092

Untitled

May 18th, 2022
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <Wire.h>
  3. #include <TimeLib.h>
  4. #include <PrayerTimes.h>
  5. #include "RTClib.h"
  6. #include <LiquidCrystal_I2C.h>
  7.  
  8. int timeAfterAthan = 1; // min
  9. int timeAfterSalat = 1; // min
  10.  
  11. int fh, fm;
  12. int dh, dm;
  13. int ah, am;
  14. int mh, mm;
  15. int ih, im;
  16.  
  17. int flag = 0;
  18. int newMin = 0;
  19.  
  20. #define inRelay 6
  21. #define outRelay 7
  22.  
  23. int nowHOUR;
  24. int nowMIN;
  25.  
  26. RTC_DS3231 rtc;
  27. LiquidCrystal_I2C lcd(0x27, 16, 2);
  28.  
  29. char daysOfTheWeek[7][12] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
  30. double times[sizeof(TimeName) / sizeof(char*)];
  31.  
  32. void setup() {
  33. Serial.begin(57600);
  34. if (! rtc.begin()) {
  35. Serial.println("Couldn't find RTC");
  36. Serial.flush();
  37. while (1) delay(10);
  38. }
  39. lcd.init();
  40. lcd.backlight();
  41. pinMode(inRelay, OUTPUT);
  42. pinMode(outRelay, OUTPUT);
  43. digitalWrite(inRelay, HIGH);
  44. digitalWrite(outRelay, HIGH);
  45.  
  46.  
  47. if (rtc.lostPower()) {
  48. Serial.println("RTC lost power, let's set the time!");
  49. rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  50. }
  51. }
  52.  
  53. void loop() {
  54. DateTime now = rtc.now();
  55.  
  56. set_calc_method(Makkah);
  57. set_asr_method(Shafii);
  58. set_high_lats_adjust_method(AngleBased);
  59. set_fajr_angle(18.5);
  60. set_isha_angle(15);
  61.  
  62. //JEDDAH MODIFIED BY DR JABER
  63. float latitude = 21.588657;
  64. float longitude = 39.219734;
  65.  
  66. get_prayer_times(now.year(), now.month(), now.day(), latitude, longitude, 3, times);
  67.  
  68. get_float_time_parts(times[0], fh, fm);
  69. get_float_time_parts(times[2], dh, dm);
  70. get_float_time_parts(times[3], ah, am);
  71. get_float_time_parts(times[5], mh, mm);
  72. get_float_time_parts(times[6], ih, im);
  73. im = im * 10;
  74. /*
  75. for (int i = 0; i < sizeof(times) / sizeof(double); i++) {
  76. //char tmp[10];
  77. int hourss, minutess;
  78. get_float_time_parts(times[i], hourss, minutess);
  79. Serial.print(i);
  80. Serial.print(" \t ");
  81. Serial.print(TimeName[i]);
  82. //Serial.print(" \t\t ");
  83. //Serial.print(times[i]);
  84. Serial.print(" \t\t");
  85. Serial.print(hourss);
  86. Serial.print(":");
  87. Serial.print(minutess);
  88. Serial.println();
  89.  
  90. }
  91. */
  92. nowHOUR = now.hour();
  93. nowMIN = now.minute();
  94. Serial.print(now.year(), DEC);
  95. Serial.print('/');
  96. Serial.print(now.month(), DEC);
  97. Serial.print('/');
  98. Serial.print(now.day(), DEC);
  99. Serial.print(" (");
  100. Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
  101. Serial.print(") ");
  102. Serial.print(nowHOUR, DEC);
  103. Serial.print(':');
  104. Serial.print(nowMIN, DEC);
  105. Serial.print(':');
  106. Serial.print(now.second(), DEC);
  107. Serial.println();
  108. lcd.clear();
  109. lcd.setCursor(0, 0);
  110. lcd.print(nowHOUR);
  111. if (nowMIN < 10) {
  112. lcd.print(":0");
  113. }
  114. else {
  115. lcd.print(":");
  116. }
  117. lcd.print(nowMIN);
  118. lcd.print(" ");
  119. lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
  120. lcd.print(" ");
  121. //Prayer Time if statments
  122. //*********************************************************************************
  123. ////////////////////////////////////////////////////////////////////
  124. if (nowHOUR <= fh) {
  125. lcd.print(fh);
  126. lcd.print(":");
  127. lcd.print(fm);
  128. if (nowHOUR == fh && nowMIN == fm) {
  129. lcd.setCursor(10, 1);
  130. lcd.print("OUT");
  131. //turn ON out Relay
  132. digitalWrite(inRelay, HIGH);
  133. digitalWrite(outRelay, LOW);
  134. }
  135. if (nowHOUR == fh && nowMIN == fm + timeAfterAthan) {
  136. lcd.setCursor(10, 1);
  137. lcd.print("IN ");
  138. //turn ON in Relay
  139. digitalWrite(inRelay, LOW);
  140. digitalWrite(outRelay, HIGH);
  141. flag = 1;
  142. }
  143. }
  144. ////////////////////////////////////////////////////////////////////
  145. //*********************************************************************************
  146. ////////////////////////////////////////////////////////////////////
  147. else if (nowHOUR <= dh) {
  148. lcd.print(dh);
  149. lcd.print(":");
  150. lcd.print(dm);
  151. if (nowHOUR == dh && nowMIN == dm) {
  152. lcd.setCursor(10, 1);
  153. lcd.print("OUT");
  154. //turn ON out Relay
  155. digitalWrite(inRelay, HIGH);
  156. digitalWrite(outRelay, LOW);
  157. }
  158. if (nowHOUR == dh && nowMIN == dm + timeAfterAthan) {
  159. lcd.setCursor(10, 1);
  160. lcd.print("IN ");
  161. //turn ON in Relay
  162. digitalWrite(inRelay, LOW);
  163. digitalWrite(outRelay, HIGH);
  164. flag = 1;
  165. }
  166. }
  167. ////////////////////////////////////////////////////////////////////
  168. //*********************************************************************************
  169. ////////////////////////////////////////////////////////////////////
  170. else if (nowHOUR <= ah) {
  171. lcd.print(ah);
  172. lcd.print(":");
  173. lcd.print(am);
  174. if (nowHOUR == ah && nowMIN == am) {
  175. lcd.setCursor(10, 1);
  176. lcd.print("OUT");
  177. //turn ON out Relay
  178. digitalWrite(inRelay, LOW);
  179. digitalWrite(outRelay, HIGH);
  180. }
  181. if (nowHOUR == ah && nowMIN == am + timeAfterAthan) {
  182. lcd.setCursor(10, 1);
  183. lcd.print("IN ");
  184. //turn ON in Relay
  185. digitalWrite(inRelay, LOW);
  186. digitalWrite(outRelay, HIGH);
  187. flag = 1;
  188. }
  189. }
  190. ////////////////////////////////////////////////////////////////////
  191. //*********************************************************************************
  192. ////////////////////////////////////////////////////////////////////
  193. else if (nowHOUR <= mh) {
  194. lcd.print(mh);
  195. lcd.print(":");
  196. lcd.print(mm);
  197. if (nowHOUR == mh && nowMIN == mm) {
  198. lcd.setCursor(10, 1);
  199. lcd.print("OUT");
  200. //turn ON out Relay
  201. digitalWrite(inRelay, HIGH);
  202. digitalWrite(outRelay, LOW);
  203. }
  204. if (nowHOUR == mh && nowMIN == mm + timeAfterAthan) {
  205. lcd.setCursor(10, 1);
  206. lcd.print("IN ");
  207. //turn ON in Relay
  208. digitalWrite(inRelay, LOW);
  209. digitalWrite(outRelay, HIGH);
  210. flag = 1;
  211. }
  212. }
  213. ////////////////////////////////////////////////////////////////////
  214. //*********************************************************************************
  215. ////////////////////////////////////////////////////////////////////
  216. else if (nowHOUR <= ih) {
  217. lcd.print(ih);
  218. lcd.print(":");
  219. lcd.print(im);
  220. if (nowHOUR == ih && nowMIN == im) {
  221. lcd.setCursor(10, 1);
  222. lcd.print("OUT");
  223. //turn ON out Relay
  224. digitalWrite(inRelay, HIGH);
  225. digitalWrite(outRelay, LOW);
  226. }
  227. if (nowHOUR == ih && nowMIN == im + timeAfterAthan) {
  228. lcd.setCursor(10, 1);
  229. lcd.print("IN ");
  230. //turn ON in Relay
  231. digitalWrite(inRelay, LOW);
  232. digitalWrite(outRelay, HIGH);
  233. flag = 1;
  234. }
  235. }
  236.  
  237. else if (nowHOUR > ih) {
  238. lcd.print(fh);
  239. lcd.print(":");
  240. lcd.print(fm);
  241. }
  242. ////////////////////////////////////////////////////////////////////
  243. //*********************************************************************************
  244. lcd.setCursor(0, 1);
  245. lcd.print(now.day());
  246. lcd.print("/");
  247. lcd.print(now.month());
  248. lcd.print("/");
  249. lcd.print(now.year());
  250. lcd.print(" ");
  251.  
  252. if (flag == 1) {
  253. newMin = newMin + 10;
  254. if (newMin >= timeAfterSalat * 60) { // 600 = 10 min
  255. lcd.setCursor(10, 1);
  256. lcd.print(" ");
  257. digitalWrite(inRelay, HIGH);
  258. digitalWrite(outRelay, HIGH);
  259. flag = 0;
  260. }
  261. }
  262.  
  263. delay(10000);
  264. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement