Make sensor initialization and measurement more dynamic by checking
which one are declared in config.h
This commit is contained in:
@@ -1,28 +1,23 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
//#define VASE_NUM 0
|
||||
|
||||
#define MOISTURE_SENSOR_A0 PC0
|
||||
#define MOISTURE_SENSOR_A1 PC1
|
||||
#define MOISTURE_SENSOR_A2 PC2
|
||||
#define MOISTURE_SENSOR_A3 PC3
|
||||
#define MOISTURE_SENSOR_A4 PC4
|
||||
#define MOISTURE_SENSOR_A5 PC5
|
||||
// NOTE: PC6 PC7 are not accessible by default on Arduino Uno R3
|
||||
// You need to use the ATMega328p on a custom PCB and use pins 1 and 2
|
||||
//#define MOISTURE_SENSOR_A6 PC6
|
||||
//#define MOISTURE_SENSOR_A7 PC7
|
||||
|
||||
// You may just connect the pumps that actually are needed in the vase
|
||||
// or define only the connected pumps on your system
|
||||
#define PUMP_D3 PD3
|
||||
#define PUMP_D4 PD4
|
||||
#define PUMP_D5 PD5
|
||||
#define PUMP_D6 PD6
|
||||
#define PUMP_D7 PD7
|
||||
//#define PUMP_D6 PD6
|
||||
//#define PUMP_D7 PD7
|
||||
|
||||
// TODO: write these to eeprom
|
||||
#define SENSOR_READINGS 5
|
||||
#define SENSORS_NUM 6
|
||||
//#define VASE_NUM 0
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,12 +3,49 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "config.h"
|
||||
|
||||
static const int8_t sensorPins[] = {
|
||||
#ifdef MOISTURE_SENSOR_A0
|
||||
MOISTURE_SENSOR_A0,
|
||||
#endif
|
||||
|
||||
#ifdef MOISTURE_SENSOR_A1
|
||||
MOISTURE_SENSOR_A1,
|
||||
#endif
|
||||
|
||||
#ifdef MOISTURE_SENSOR_A2
|
||||
MOISTURE_SENSOR_A2,
|
||||
#endif
|
||||
|
||||
#ifdef MOISTURE_SENSOR_A3
|
||||
MOISTURE_SENSOR_A3,
|
||||
#endif
|
||||
|
||||
#ifdef MOISTURE_SENSOR_A4
|
||||
MOISTURE_SENSOR_A4,
|
||||
#endif
|
||||
|
||||
#ifdef MOISTURE_SENSOR_A5
|
||||
MOISTURE_SENSOR_A5,
|
||||
#endif
|
||||
|
||||
#ifdef MOISTURE_SENSOR_A6
|
||||
MOISTURE_SENSOR_A6,
|
||||
#endif
|
||||
|
||||
#ifdef MOISTURE_SENSOR_A7
|
||||
MOISTURE_SENSOR_A7,
|
||||
#endif
|
||||
};
|
||||
|
||||
#define SENSORS_NUM (sizeof(sensorPins) / sizeof(sensorPins[0]))
|
||||
|
||||
extern volatile bool readSensors;
|
||||
|
||||
void sensorsInit(void);
|
||||
void triggerMoistureRead(void);
|
||||
int16_t moistureAverage(int8_t sensorPin);
|
||||
int16_t moistureRead(void);
|
||||
|
||||
extern volatile bool readSensors;
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user