hydroponic-controller/include/ec.h

41 lines
852 B
C

#ifndef _EC_H_
#define _EC_H_
#include <Arduino.h>
#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);
}
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