-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharduino_sunrise.ino
85 lines (69 loc) · 1.8 KB
/
arduino_sunrise.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* Sunrise alarm clock
By: Tim Forbes
Latest update: October 30, 2019
*/
#include "./arduino_sunrise.h"
/* Script Start
*/
void setup()
{
Serial.begin(115200);
Serial.println("Clock startup");
pinMode(TFT_CS, OUTPUT);
digitalWrite(TFT_CS, HIGH);
tft.begin();
tft.setRotation(3);
tft.background(bg_color.r, bg_color.g, bg_color.b);
// Define the LED strip driver and color calibration
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
// Button Mode change
pinMode(BTN_OK, INPUT_PULLUP);
pinMode(BTN_LEFT, INPUT_PULLUP);
pinMode(BTN_RIGHT, INPUT_PULLUP);
// Verify RTC exists
if (!rtc.begin())
{
Serial.println("Couldn't find RTC");
tft.stroke(255, 0, 0);
tft.text("RTC not found!", 0, 0);
while (1)
;
}
// Set the RTC if necessary
if (!rtc.isrunning())
{
Serial.println("RTC not running! Setting to last compile DateTime: " + String(F(__DATE__)) + " at " + String(F(__TIME__)));
// set the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
Serial.println("Setup complete!");
Serial.print("Current RTC Date/Time: ");
Serial.print(now_now.year());
Serial.print("/");
Serial.print(now_now.month());
Serial.print("/");
Serial.print(now_now.day());
Serial.print(" @ ");
Serial.print(now_now.hour());
Serial.print(":");
Serial.print(now_now.minute());
Serial.print(":");
Serial.println(now_now.second());
Serial.print("Unix time: ");
Serial.println(now_now.unixtime());
}
void loop()
{
now_now = rtc.now();
// Check if any buttons are being pressed
checkBtnOk();
checkBtnLeft();
checkBtnRight();
// Sunrise currently active, sleeping, or off?
checkModeActive();
// Update LED
updateLed();
// Update LCD
updateLcd();
now_last = now_now;
}