This repository was archived by the owner on May 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20_setup.ino
59 lines (51 loc) · 1.39 KB
/
20_setup.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
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
pinMode(_2posSw, INPUT_PULLUP);
pinMode(pot, INPUT);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("Aquatroller 1.0");
//delay(800);
if (! rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (rtc.lostPower()) {
Serial.println("RTC lost power, let's set the time!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("CHECKING TIME...");
delay(1000);
DateTime now = rtc.now();
if (checkDaytime()) {
lcd.setCursor(0, 1);
lcd.print("DAY MODE");
lightOn = 1;
lcd.setBacklight(HIGH);
uint8_t brightness = 0;
uint8_t lastPercent;
delay(1500);
while (brightness < maxPWMsteps) {
analogWrite(ledPin, brightness);
uint16_t percent = map(brightness, 0, maxPWMsteps, 0, 100); //even though the percent var can only go up to 100, it still occupies more memory than 8bits uint8_t so must use 16nit mem allocation.
if (percent != lastPercent) {
sprintf(illuminate, "ILLUMINATING %d%%", percent);
lcd.setCursor(0, 1);
lcd.print(illuminate);
}
lastPercent = percent;
brightness++;
delay(fadeDelay);
}
} else {
lcd.setCursor(0, 1);
lcd.print("NIGHT MODE");
delay(2000);
lightOn = 0;
lcd.setBacklight(LOW);
updateLCD();
}
}