Advertisement
safwan092

Untitled

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