Humidistat
Arduino firmware for a humidistat (humidity controller)
Loading...
Searching...
No Matches
FlowSensor.cpp
Go to the documentation of this file.
1
#include <Arduino.h>
2
3
#include "
FlowSensor.h
"
4
#include "
imath.h
"
5
6
FlowSensor::FlowSensor
(uint8_t pin) : pin(pin) {}
7
8
double
FlowSensor::readFlowrate
()
const
{
9
double
value = analogRead(
pin
);
10
11
// Calculate flowrate from voltage using polynomial approximation
12
return
(
coeffs
[0] *
ipow
(value, 5)
13
+
coeffs
[1] *
ipow
(value, 4)
14
+
coeffs
[2] *
ipow
(value, 3)
15
+
coeffs
[3] *
ipow
(value, 2)
16
+
coeffs
[4] * value
17
+
coeffs
[5]);
18
}
FlowSensor.h
FlowSensor::coeffs
static constexpr double coeffs[]
Coefficients of the polynomial approximation to the sensor response (and voltage mapping)
Definition
FlowSensor.h:13
FlowSensor::pin
const uint8_t pin
Definition
FlowSensor.h:11
FlowSensor::FlowSensor
FlowSensor(uint8_t pin)
Constructor.
Definition
FlowSensor.cpp:6
FlowSensor::readFlowrate
double readFlowrate() const
Read the flow rate.
Definition
FlowSensor.cpp:8
imath.h
ipow
constexpr T ipow(T base, unsigned int pow)
Constexpr function for computing integer power.
Definition
imath.h:10
src
sensor
FlowSensor.cpp
Generated by
1.12.0