hydroponic-controller/include/ec.h

53 lines
1.4 KiB
C
Raw Normal View History

2023-04-17 19:32:34 +00:00
#ifndef _EC_H_
#define _EC_H_
#include <Arduino.h>
2023-04-17 19:33:05 +00:00
#define EC_PIN_RELAY_PROBE 27
#define EC_PIN_RELAY_CALIBRATION 26
#define EC_PIN_RELAY_RANGE 25
#define EC_CALIBRATION_RESISTOR_NC 100000
#define EC_CALIBRATION_RESISTOR_NO 1000
2023-04-17 19:32:34 +00:00
#define EC_PIN_ADC 4
#define EC_PIN_FREQ 5
#define EC_PWM_CH 0
#define EC_RESOLUTION 8
#define EC_FREQUENCY 5000
#define EC_ARRAY_SIZE 1024
uint16_t ec_array[EC_ARRAY_SIZE];
uint16_t ec_array_pos=0;
unsigned long last_read_ec=0;
#define EC_READ_INTERVAL 1
void ec_setup() {
pinMode(EC_PIN_ADC,INPUT);
ledcSetup(EC_PWM_CH, EC_FREQUENCY, EC_RESOLUTION);
ledcAttachPin(EC_PIN_FREQ, EC_PWM_CH);
ledcWrite(EC_PWM_CH, 127);
2023-04-17 19:33:05 +00:00
pinMode(EC_PIN_RELAY_PROBE,OUTPUT); //LOW=Calibration/idle, HIGH=Probe connected
pinMode(EC_PIN_RELAY_CALIBRATION,OUTPUT); //LOW=NC Calibration Resistor, HIGH=NO Calib. Res.
pinMode(EC_PIN_RELAY_RANGE,OUTPUT); //LOW=NC Range Resistor, HIGH=NO Range Resistor
digitalWrite(EC_PIN_RELAY_PROBE,LOW);
digitalWrite(EC_PIN_RELAY_CALIBRATION,LOW);
digitalWrite(EC_PIN_RELAY_RANGE,LOW);
2023-04-17 19:32:34 +00:00
}
void ec_loop(unsigned long loopmillis, unsigned long pInterval) {
if (loopmillis>last_read_ec+pInterval) {
last_read_ec=loopmillis;
ec_array_pos++;
flag_print= ec_array_pos==EC_ARRAY_SIZE;
ec_array_pos%=EC_ARRAY_SIZE;
ec_array[ec_array_pos]=analogRead(EC_PIN_ADC);
//Serial.print(ec_array[ec_array_pos]); Serial.print(" ");
}
}
#endif