-
Notifications
You must be signed in to change notification settings - Fork 0
/
plant-waterer.ino
52 lines (44 loc) · 1.25 KB
/
plant-waterer.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
int water_time = 5; // in seconds
int water_delay = 1; // in minutes
int reset_button_pin = 2;
int water_button_pin = 3;
int water_pump_control = 9;
unsigned long time;
unsigned long start_time = 0;
void setup() {
pinMode(reset_button_pin, INPUT);
pinMode(water_button_pin, INPUT);
pinMode(water_pump_control, OUTPUT);
Serial.begin(9600);
water_time *= 1000; // turn into seconds
water_delay *= 60000; // turn into minutes
}
void loop() {
time = millis();
if (time >= water_delay + start_time) {
digitalWrite(water_pump_control, HIGH);
if (time >= water_delay + start_time + water_time) {
start_time = time;
digitalWrite(water_pump_control, LOW);
}
}
if (digitalRead(water_button_pin)) {
Serial.println("Pumping water (button press).");
digitalWrite(water_pump_control, HIGH);
delay(water_time);
digitalWrite(water_pump_control, LOW);
}
if (digitalRead(reset_button_pin)) {
Serial.println("Resetting water timer (button press).");
digitalWrite(water_pump_control, LOW);
start_time = millis();
}
}
void debug() {
Serial.println("Millis: ");
Serial.print(millis());
Serial.print(", Start time: ");
Serial.print(start_time);
Serial.print(", ");
Serial.print(water_delay - start_time);
}