Advertisement
safwan092

Untitled

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