Aruna
Rain40x16.cpp
Go to the documentation of this file.
1 //
2 // Created by noeel on 22-12-20.
3 //
4 
5 #include <math.h>
7 
9 
10 }
11 
13  int16_t mV;
14  err_t e;
15  e = adc->read_voltage(mV);
16  water_level_in_mm = voltage_to_mm(mV);
17  return e;
18 }
19 
21 // TODO vcc etc as parameters
22  const int16_t sensor_length_mm = 40;
23  const int16_t max_voltage_when_dry = 20;
24  const int16_t voltage_at_min = 1000;
25  const int16_t voltage_at_max = 3300;
26 
27  const int16_t voltage_diff = voltage_at_max - voltage_at_min;
28 
29  if (mV < max_voltage_when_dry)
30  return 0;
31  if (mV < voltage_at_min) {
32 // voltage is in grey space.
33  return 1;
34  }
35 // TODO this conversion is linear while in real-life it is not
36  return ceilf(((float) mV - (float) voltage_at_min) * ((float) sensor_length_mm / (float) voltage_diff));
37 
38 }
int16_t voltage_to_mm(uint16_t mV)
Definition: Rain40x16.cpp:20
err_t read_voltage(T &mV)
Read voltage level of input.
Rain40x16(driver::ADC *adc)
Rainlevel sensor 40mmx16mm DC3-5V Currently hardcoded for 3.3V.
Definition: Rain40x16.cpp:8
Analogue digital converter.
Definition: ADC.h:19
driver::ADC * adc
Definition: Rain40x16.h:14
err_t get_water_level(uint16_t &water_level_in_mm) override
Get water level in millimeters of the sensor.
Definition: Rain40x16.cpp:12