WATERING.ino 978 B

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