Skip to content

Commit 0193b36

Browse files
committed
add watering unit
1 parent cb08702 commit 0193b36

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

examples/Unit/WATERING/WATERING.ino

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
Description: Read the ADC value measured by the Watering Unit, and the water pump can be switched on and off through the middle button.
3+
*/
4+
5+
6+
#include <M5Stack.h>
7+
8+
#define INPUT_PIN 36
9+
#define PUMP_PIN 26
10+
11+
bool flag = true;
12+
int rawADC;
13+
14+
void setup() {
15+
M5.begin();
16+
M5.Lcd.setTextColor(GREEN);
17+
M5.Lcd.setTextSize(3);
18+
M5.Lcd.setTextDatum(TC_DATUM);
19+
M5.Lcd.drawString("Watering TEST", 160, 20, 1);
20+
M5.Lcd.drawString("ON/OFF PUMP", 160, 200, 1);
21+
pinMode(INPUT_PIN,INPUT);
22+
pinMode(PUMP_PIN,OUTPUT);
23+
pinMode(25,OUTPUT);
24+
digitalWrite(25,0);
25+
}
26+
27+
char info[30];
28+
29+
void loop() {
30+
rawADC = analogRead(INPUT_PIN);
31+
M5.lcd.fillRect(80, 100, 240, 50, BLACK);
32+
M5.Lcd.setCursor(80, 100);
33+
M5.Lcd.print("ADC: "+ String(rawADC));
34+
Serial.print("Watering ADC value: ");
35+
Serial.println(rawADC);
36+
if(M5.BtnB.wasPressed()){
37+
digitalWrite(PUMP_PIN,flag);
38+
flag = !flag;
39+
}
40+
M5.update();
41+
delay(100);
42+
}

0 commit comments

Comments
 (0)