DIY fertilizer mixer and plant watering machine https://www.xythobuz.de/giessomat.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Plants.cpp 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #include <Arduino.h>
  2. #include "Plants.h"
  3. // valves: no of plants + 1 for water inlet
  4. // pumps: no of fertilizers
  5. // switches: 2, low and high level
  6. Plants::Plants(int valve_count, int pump_count, int switch_count) :
  7. valves(valve_count), pumps(pump_count), switches(switch_count) {
  8. }
  9. void Plants::setValvePins(int pins[]) {
  10. valves.setPinNumbers(pins);
  11. valves.setOutput();
  12. valves.setAll(false);
  13. }
  14. void Plants::setPumpPins(int pins[]) {
  15. pumps.setPinNumbers(pins);
  16. pumps.setOutput();
  17. pumps.setAll(false);
  18. }
  19. void Plants::setSwitchPins(int pins[], bool pullup) {
  20. switches.setPinNumbers(pins);
  21. switches.setInput(pullup);
  22. }
  23. void Plants::abort(void) {
  24. closeWaterInlet();
  25. stopAllFertilizers();
  26. stopAllPlants();
  27. }
  28. Plants::Waterlevel Plants::getWaterlevel(void) {
  29. bool low = !switches.getPin(0);
  30. bool high = !switches.getPin(1);
  31. if ((!low) && (!high)) {
  32. return empty;
  33. } else if (low && (!high)) {
  34. return inbetween;
  35. } else if (low && high) {
  36. return full;
  37. } else {
  38. return invalid;
  39. }
  40. }
  41. void Plants::openWaterInlet(void) {
  42. valves.setPin(countPlants(), true);
  43. }
  44. void Plants::closeWaterInlet(void) {
  45. valves.setPin(countPlants(), false);
  46. }
  47. int Plants::countFertilizers(void) {
  48. return pumps.getSize();
  49. }
  50. void Plants::startFertilizer(int id) {
  51. if ((id >= 0) && (id < countFertilizers())) {
  52. pumps.setPin(id, true);
  53. }
  54. }
  55. void Plants::stopFertilizer(int id) {
  56. if ((id >= 0) && (id < countFertilizers())) {
  57. pumps.setPin(id, false);
  58. }
  59. }
  60. void Plants::stopAllFertilizers(void) {
  61. for (int i = 0; i < countFertilizers(); i++) {
  62. stopFertilizer(i);
  63. }
  64. }
  65. int Plants::countPlants(void) {
  66. return valves.getSize() - 1;
  67. }
  68. void Plants::startPlant(int id) {
  69. if ((id >= 0) && (id < countPlants())) {
  70. valves.setPin(id, true);
  71. }
  72. }
  73. void Plants::stopPlant(int id) {
  74. if ((id >= 0) && (id < countPlants())) {
  75. valves.setPin(id, false);
  76. }
  77. }
  78. void Plants::stopAllPlants(void) {
  79. for (int i = 0; i < countPlants(); i++) {
  80. stopPlant(i);
  81. }
  82. }