Penjadwalan Pembacaan Sensor Berbasis RTC DS3231
Penjadwalan Pembacaan Sensor Berbasis RTC DS3231
1 if (detikSebelumnya != now.second() )
2 {
3 detikSebelumnya = now.second();
4 bacaSensor();
5 }
1 if (!(now.second() % periodaBacaSensor)
2 {
3 bacaSensor();
4 }
1 if (now.getEpoch() == databaseJadwal[i].
2 {
3 bacaSensor();
4 }
1 #define pinSensor A0
2
3 #include <Wire.h>
4 #include "Sodaq_DS3231.h"
5
6 DateTime set = {2020, 2, 22, 7, 0, 0, 1};
7 DateTime now;
8 DateTime databaseJadwal[] = {
9 {2020, 2, 22, 7, 0, 3, 1},
10 {2020, 2, 23, 7, 0, 0, 1},
11 {2020, 2, 24, 7, 0, 0, 1},
12 {2020, 2, 25, 7, 0, 0, 1},
13 {2020, 2, 26, 7, 0, 0, 1},
14 {2020, 2, 27, 7, 0, 0, 1},
15 };
16 byte detikSebelumnya;
17 byte menitSebelumnya;
18
19 #define periodaBacaSensor 5//detik
20
21 void bacaSensor()
22 {
23 analogRead(pinSensor);
24 }
25
26 void setup() {
27 Serial.begin(9600);
28 Serial.println("Penjadwalan pembacaan sen
29 Serial.println("https://www.project.semes
30 Serial.println();
31
32 Wire.begin();
33 rtc.begin();
34 now = rtc.now();
35 // if (now.year() == 2000)
36 {
37 rtc.setDateTime(set);
38 }
39 }
40
41 void loop() {
42 now = rtc.now();
43
44 if (detikSebelumnya != now.second() )
45 {
46
47 char bufWaktu[32];
48 sprintf(bufWaktu, "%02d:%02d:%02d %02d‐
49 Serial.println(bufWaktu);
50
51 //pembacaan setiap detik
52 detikSebelumnya = now.second();
53 Serial.println("setiap detik");
54 bacaSensor();
55
56
←
→