-
Notifications
You must be signed in to change notification settings - Fork 0
/
temp_limit_using_buttons.ino
190 lines (158 loc) · 5.01 KB
/
temp_limit_using_buttons.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
void read_limits_values_from_eeprom(void) {
if (initalization_templimit == false) {
for (int i = 0; i < NUMBER_OF_SENSORS; i++) {
temp_limit[i] = read_from_eeprom(i * 2);
}
}
}
void set_up_limits() {
display.setTextColor(WHITE);
display.clearDisplay();
display.display();
display.setTextSize(1);
display.setCursor(0, 0);
display.display();
Serial.println("1111");
start2 = millis();
while (1) {
now2 = millis();
elapsed2 = now2 - start2;
if (elapsed2 > timeout2) break;
Serial.println("22222");
set_temp_limit(0);
break;
if (digitalRead(buttonPinBack) == 1) break;
}
display.clearDisplay();
display.display();
}
int set_temp_limit(int index) {
if (initalization_templimit == false) {
for (int i = 0; i < NUMBER_OF_SENSORS; i++) {
temp_limit[i] = read_from_eeprom(i * 2);
}
initalization_templimit = true;
}
if (index < NUMBER_OF_SENSORS) {
display.clearDisplay();
display.display();
display.setTextSize(1);
display.setCursor(0, 0);
Serial.print("Set limits for sensor/index "); display.print("Psigio "); display.print(index + 1);
Serial.print(index);
Serial.print(" it has this limit ");
Serial.print(read_from_eeprom(index * 2)); display.print(" Orio thermokrasias ");
if (read_from_eeprom(index * 2) == 0) {
display.print(" OFF");
} else display.print(read_from_eeprom(index * 2));
Serial.print("\n"); display.display();
}
if (elapsed2 > timeout2) return 0;;
delay(200);
if (index >= NUMBER_OF_SENSORS) {
for (int i = 0; i < NUMBER_OF_SENSORS; i++) {
Serial.println(temp_limit[i]);
save_to_eeprom(i * 2, temp_limit[i]);
}
Serial.println("Read from eeprom");
for (int i = 0; i < NUMBER_OF_SENSORS; i++) {
Serial.println(read_from_eeprom(i * 2));
}
boolean initalization_templimit = false;
Serial.println("Temp limits are updated");
return 1;
}
while (1) {
buttonStateUp = digitalRead(buttonPinUp);
// compare the buttonState to its previous state
if (buttonStateUp != lastButtonStateUp) {
// if the state has changed, increment the counter
if (buttonStateUp == HIGH) {
temp_limit[index]++;
display.clearDisplay();
Serial.println(temp_limit[index]);
display.display();
display.setTextSize(1);
display.setCursor(0, 0);
display.print("Psigio ");
display.print(index + 1);
display.print(" Orio thermokrasias ");
if (temp_limit[index] == 0) {
display.println(" OFF");
}
else {
display.print(temp_limit[index]);
display.print("C");
}
display.display();
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state,
//for next time through the loop
lastButtonStateUp = buttonStateUp;
buttonStateDown = digitalRead(buttonPinDown);
// compare the buttonState to its previous state
if (buttonStateDown != lastButtonStateDown) {
// if the state has changed, increment the counter
if (buttonStateDown == HIGH) {
// if the current state is HIGH then the button
// wend from off to on:
temp_limit[index]--;
display.clearDisplay();
Serial.println(temp_limit[index]);
display.display();
display.setTextSize(1);
display.setCursor(0, 0);
display.print("Psigio ");
display.print(index + 1);
display.print(" Orio thermokrasias ");
if (temp_limit[index] == 0) {
display.println(" OFF");
}
else {
display.print(temp_limit[index]);
display.print("C");
}
display.display();
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state,
//for next time through the loop
lastButtonStateDown = buttonStateDown;
buttonStateEnter = digitalRead(buttonPinEnter);
// compare the buttonState to its previous state
if (buttonStateEnter != lastButtonStateEnter) {
// if the state has changed, increment the counter
if (buttonStateEnter == HIGH) {
temp_limit[index] = temp_limit[index];
index++;
set_temp_limit(index);
break;
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state,
//for next time through the loop
lastButtonStateEnter = buttonStateEnter;
buttonStateBack = digitalRead(buttonPinBack);
// compare the buttonState to its previous state
if (buttonStateBack != lastButtonStateBack) {
// if the state has changed, increment the counter
if (buttonStateBack == HIGH and index != 0) {
index--;
set_temp_limit(index);
break;
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state,
//for next time through the loop
lastButtonStateBack = buttonStateBack;
}
}