199 lines
4 KiB
C++
199 lines
4 KiB
C++
#pragma once
|
|
#include <Arduino.h>
|
|
|
|
struct Sensor {
|
|
/// Which analog pin this is connected to (A0, A1, ...)
|
|
uint8_t pin;
|
|
/// The value sensors read when completely dry
|
|
int calibration_dry;
|
|
/// The value sensors read when completely wet
|
|
int calibration_wet;
|
|
/// Pot group index this sensor belongs to
|
|
unsigned int pot_group;
|
|
};
|
|
|
|
struct Group {
|
|
/// Enable or disable the group
|
|
bool enabled;
|
|
/// Which pin the indicator light is connected to
|
|
uint8_t led_pin;
|
|
};
|
|
|
|
struct Valve {
|
|
/// The digital pin this valve is connected to
|
|
uint8_t pin;
|
|
/// Pot group index this valve belongs to
|
|
unsigned int pot_group;
|
|
};
|
|
|
|
constexpr unsigned int SECOND = 1000;
|
|
constexpr unsigned int MINUTE = SECOND * 60;
|
|
constexpr unsigned int HOUR = MINUTE * 60;
|
|
|
|
constexpr unsigned int MEASUREMENT_COUNT = 3;
|
|
constexpr int MEASUREMENT_DELAY = 100;
|
|
|
|
/// Pots will always be watered below this humidity
|
|
constexpr int MIN_HUMIDITY_PERCENT = 30;
|
|
|
|
/// Pots will never be watered above this humidity
|
|
constexpr int MAX_HUMIDITY_PERCENT = 70;
|
|
|
|
/// the amount of time a valve needs to open/close
|
|
constexpr int VALVE_DELAY_MS = 1 * SECOND / 4;
|
|
|
|
/// the amount of time the pump needs to szcttart/stop
|
|
constexpr int PUMP_DELAY_MS = 1 * SECOND / 4;
|
|
|
|
/// the amount of time to water the plot (valve open and pump running)
|
|
constexpr int WATER_TIME_MS = 1 * SECOND;
|
|
|
|
/// how long to wait between loops
|
|
constexpr int LOOP_DELAY_MS = 1 * SECOND; // TODO set higher once it is working
|
|
|
|
/// minimum amount of time to wait between watering each pot, even when minimum wetness has been reached
|
|
constexpr int MIN_WATERING_INTERVAL_MS = 10 * SECOND; // TODO set higher once it is working
|
|
|
|
/// maximum amount of time to wait between watering each pot, as long as maximum wetness has not been reaached
|
|
constexpr int MAX_WATERING_INTERVAL_MS = 24 * HOUR;
|
|
|
|
constexpr uint8_t PUMP_PIN = 7;
|
|
constexpr uint8_t PUMP_LED_PIN = 3;
|
|
|
|
constexpr uint8_t OK_LED_PIN = 2;
|
|
|
|
constexpr struct Group GROUPS[] = {
|
|
{ // 0
|
|
.enabled = true,
|
|
.led_pin = 22,
|
|
}, { // 1
|
|
.enabled = false,
|
|
.led_pin = 24,
|
|
}, { // 2
|
|
.enabled = false,
|
|
.led_pin = 26,
|
|
}, { // 3
|
|
.enabled = false,
|
|
.led_pin = 28,
|
|
}, { // 4
|
|
.enabled = true,
|
|
.led_pin = 30,
|
|
}, { // 5
|
|
.enabled = false,
|
|
.led_pin = 32,
|
|
}, { // 6
|
|
.enabled = false,
|
|
.led_pin = 34,
|
|
}, { // 7
|
|
.enabled = false,
|
|
.led_pin = 36,
|
|
}, { // 8
|
|
.enabled = false,
|
|
.led_pin = 38,
|
|
}, { // 9
|
|
.enabled = true,
|
|
.led_pin = 40,
|
|
}, { // 10
|
|
.enabled = false,
|
|
.led_pin = 42,
|
|
}, { // 11
|
|
.enabled = false,
|
|
.led_pin = 44,
|
|
}, { // 12
|
|
.enabled = true,
|
|
.led_pin = 46,
|
|
}, { // 13
|
|
.enabled = true,
|
|
.led_pin = 48,
|
|
}, { // 14
|
|
.enabled = false,
|
|
.led_pin = 50,
|
|
}, { // 15
|
|
.enabled = false,
|
|
.led_pin = 52,
|
|
},
|
|
};
|
|
|
|
constexpr struct Sensor SENSORS[] = {
|
|
{
|
|
.pin = A0,
|
|
.calibration_dry = 540,
|
|
.calibration_wet = 250,
|
|
.pot_group = 0,
|
|
}, {
|
|
.pin = A4,
|
|
.calibration_dry = 520,
|
|
.calibration_wet = 100,
|
|
.pot_group = 4,
|
|
}, {
|
|
.pin = A9,
|
|
.calibration_dry = 520,
|
|
.calibration_wet = 100,
|
|
.pot_group = 9,
|
|
}, {
|
|
.pin = A12,
|
|
.calibration_dry = 520,
|
|
.calibration_wet = 100,
|
|
.pot_group = 12,
|
|
}, {
|
|
.pin = A13,
|
|
.calibration_dry = 520,
|
|
.calibration_wet = 100,
|
|
.pot_group = 13,
|
|
},
|
|
|
|
// the rest of A0-A15 are not used
|
|
};
|
|
|
|
constexpr struct Valve VALVES[] = {
|
|
{
|
|
.pin = 23,
|
|
.pot_group = 0,
|
|
}, {
|
|
.pin = 25,
|
|
.pot_group = 1,
|
|
}, {
|
|
.pin = 27,
|
|
.pot_group = 2,
|
|
}, {
|
|
.pin = 29,
|
|
.pot_group = 3,
|
|
}, {
|
|
.pin = 31,
|
|
.pot_group = 4,
|
|
}, {
|
|
.pin = 33,
|
|
.pot_group = 5,
|
|
}, {
|
|
.pin = 35,
|
|
.pot_group = 6,
|
|
}, {
|
|
.pin = 37,
|
|
.pot_group = 7,
|
|
}, {
|
|
.pin = 39,
|
|
.pot_group = 8,
|
|
}, {
|
|
.pin = 41,
|
|
.pot_group = 9,
|
|
}, {
|
|
.pin = 43,
|
|
.pot_group = 10,
|
|
}, {
|
|
.pin = 45,
|
|
.pot_group = 11,
|
|
}, {
|
|
.pin = 47,
|
|
.pot_group = 12,
|
|
}, {
|
|
.pin = 49,
|
|
.pot_group = 13,
|
|
}, {
|
|
.pin = 51,
|
|
.pot_group = 14,
|
|
}, {
|
|
.pin = 53,
|
|
.pot_group = 15,
|
|
}
|
|
};
|