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
6FlowSensor::FlowSensor(uint8_t pin) : pin(pin) {}
7
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}
static constexpr double coeffs[]
Coefficients of the polynomial approximation to the sensor response (and voltage mapping)
Definition FlowSensor.h:13
const uint8_t pin
Definition FlowSensor.h:11
FlowSensor(uint8_t pin)
Constructor.
Definition FlowSensor.cpp:6
double readFlowrate() const
Read the flow rate.
Definition FlowSensor.cpp:8
constexpr T ipow(T base, unsigned int pow)
Constexpr function for computing integer power.
Definition imath.h:10