-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTinaco.ino
76 lines (69 loc) · 2.07 KB
/
Tinaco.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
/*
Tinaco
*/
// constants won't change. They're used here to
// set pin numbers:
const int ledPins[] = {
2, 3, 4, 5, 6
}; // an array of pin numbers to which LEDs are attached
const int btnLed = 13;
const int levelPins[] = {
7, 8, 9, 10
}; // an array of pin numbers to which LEDs are attached
const int pushBtn = 11;
const int relayPin = 12;
const int pinCount = 5; // the number of pins (i.e. the length of the array)
// variables will change:
int waterLevelState = 0; // variable for reading the pushbutton status
int buttonState = 0;
int currentWaterLevel;
void setup() {
// initialize the LED pins as an output:
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
pinMode(btnLed, OUTPUT);
pinMode(relayPin, OUTPUT);
// initialize the pushbutton pin as an input:
for (int thisPin = 0; thisPin < pinCount; thisPin++) {
pinMode(levelPins[thisPin], INPUT);
}
pinMode(pushBtn, INPUT);
}
void loop() {
currentWaterLevel = 0;
for (int currentSet = 0; currentSet < 4; currentSet++) {
waterLevelState = digitalRead(levelPins[currentSet]);
if (waterLevelState == HIGH) {
// turn LED on:
digitalWrite(ledPins[currentSet + 1], HIGH);
currentWaterLevel = currentSet + 1;
} else {
// turn LED off:
digitalWrite(ledPins[currentSet + 1], LOW);
}
}
if (currentWaterLevel == 0) {
digitalWrite(ledPins[0], HIGH);
} else {
digitalWrite(ledPins[0], LOW);
}
buttonState = digitalRead(pushBtn);
if (buttonState == HIGH && currentWaterLevel < 4) {
digitalWrite(relayPin, LOW);
digitalWrite(btnLed, HIGH);
for (int currentLoading = currentWaterLevel; currentLoading < pinCount; currentLoading++) {
digitalWrite(ledPins[currentLoading], HIGH);
delay(200);
}
} else if (buttonState == HIGH && currentWaterLevel == 4) {
digitalWrite(relayPin, HIGH);
digitalWrite(btnLed, LOW);
delay(150);
digitalWrite(btnLed, HIGH);
delay(150);
} else {
digitalWrite(relayPin, HIGH);
digitalWrite(btnLed, LOW);
}
}