Add water level detection

master
shark 5 years ago
parent 1f1d0cfafa
commit 33bdfed478

@ -421,11 +421,7 @@ ISR (WDT_vect)
void checkBat() {
if(debug) {
String out = "[ OK ] Battery: ";
int y = 0;
for(int x = 0; x < 20; x++) {
y += analogRead(0);
delay(10);
}
int y = checkPin(0, 20);
if(analogRead(1) > 910) {
out += "Using solar power";
} else {
@ -438,11 +434,7 @@ void checkBat() {
printFastCText(out);
} else {
String out = "Battery: ";
int y = 0;
for(int x = 0; x < 20; x++) {
y += analogRead(0);
delay(10);
}
int y = checkPin(0, 20);
if(analogRead(1) > 910) {
out += "Using solar.";
} else {
@ -452,6 +444,27 @@ void checkBat() {
tft.fillRect(160, 0, 160, 20, ILI9341_WHITE);
tft.drawString(out.c_str(), 162, 2, 2);
}
// check water level
// A15: Top
// A13: Bottom
// 47: Power
digitalWrite(47, HIGH);
int a = checkPin(15, 20);
int b = checkPin(14, 20);
int c = checkPin(13, 20);
digitalWrite(47, LOW);
if(c > 200) drawButton(140, 2, 16, 16, "", ILI9341_RED);
if(b > 200) drawButton(140, 2, 16, 16, "", ILI9341_YELLOW);
if(a > 200) drawButton(140, 2, 16, 16, "", ILI9341_GREEN);
}
int checkPin(int pin, int count) {
int out = 0;
for (int x = 0; x < count, x++) {
out += analogRead(pin);
delay(10);
}
return out / count;
}
void runWater() {
@ -459,9 +472,11 @@ void runWater() {
upd = true;
pinMode(7, OUTPUT);
digitalWrite(7, HIGH);
delay(1000);
getMoisture();
if(s1 && map(soil1.touchRead(0), 0, 1023, 0, 100) <= 50) {
int td = 50 - map(soil1.touchRead(0), 0, 1023, 0, 100);
td *= 5;
String out = "[ INFO ] Running water on box 1 for ";
out += td / 10.0;
out += " sec.";
@ -472,6 +487,7 @@ void runWater() {
}
if(s2 && map(soil2.touchRead(0), 0, 1023, 0, 100) <= 50) {
int td = 50 - map(soil2.touchRead(0), 0, 1023, 0, 100);
td *= 5;
String out = "[ INFO ] Running water on box 2 for ";
out += td / 10.0;
out += " sec.";
@ -482,6 +498,7 @@ void runWater() {
}
if(s3 && map(soil3.touchRead(0), 0, 1023, 0, 100) <= 50) {
int td = 50 - map(soil3.touchRead(0), 0, 1023, 0, 100);
td *= 5;
String out = "[ INFO ] Running water on box 3 for ";
out += td / 10.0;
out += " sec.";
@ -492,6 +509,7 @@ void runWater() {
}
if(s4 && map(soil4.touchRead(0), 0, 1023, 0, 100) <= 50) {
int td = 50 - map(soil4.touchRead(0), 0, 1023, 0, 100);
td *= 5;
String out = "[ INFO ] Running water on box 4 for ";
out += td / 10.0;
out += " sec.";

Loading…
Cancel
Save