GY-63_MS5611/libraries/rain/rain.h

90 lines
2.3 KiB
C
Raw Normal View History

2022-12-04 11:55:37 -05:00
#pragma once
//
// FILE: rain.h
// AUTHOR: Rob Tillaart
2023-01-20 11:42:39 -05:00
// VERSION: 0.1.3
2022-12-04 11:55:37 -05:00
// DATE: 2022-11-23
// PURPOSE: Arduino library for rain sensor (analog).
// URL: https://github.com/RobTillaart/RAIN
// https://www.tinytronics.nl/shop/nl/sensoren/vloeistof/regensensor
#include "Arduino.h"
2023-01-20 11:42:39 -05:00
#define RAIN_LIB_VERSION (F("0.1.3"))
2022-12-04 11:55:37 -05:00
class RAIN
{
public:
2022-12-06 10:57:55 -05:00
// powerPin is optional, 255 == not used => see readme.md
2023-01-20 11:42:39 -05:00
RAIN(uint8_t analogPort, uint8_t powerPin = 255);
2022-12-04 11:55:37 -05:00
// set the ADC parameters
// can be changed runtime, e.g if voltage fluctuates.
bool begin(float maxVoltage, uint16_t maxSteps);
2023-01-20 11:42:39 -05:00
// returns steps as float, e.g can be 456.33
2022-12-04 11:55:37 -05:00
float raw(uint8_t times = 1);
// returns voltage
2022-12-06 10:57:55 -05:00
// the lower the voltage the wetter.
2022-12-04 11:55:37 -05:00
float read(uint8_t times = 1);
// ANALYSIS
2023-01-20 11:42:39 -05:00
//
2022-12-06 10:57:55 -05:00
// read the sensor when it is dry to get a reference (calibration).
// will be used by percentage(), can be used to setLevel().
2023-01-20 11:42:39 -05:00
// NOTE: dryRef is default maxVoltage parameter from begin()
2022-12-06 10:57:55 -05:00
void setDryReference(float dryRef);
float getDryReference();
// returns last read value as percentage of DryReference (if set).
// indicating wetness 0 == DRY 100 == WET
// percentage assumes / implies "linear" behaviour
2022-12-04 11:55:37 -05:00
float percentage();
2022-12-06 10:57:55 -05:00
// delta with respect to previous read().
2022-12-06 05:26:48 -05:00
float delta();
2022-12-04 11:55:37 -05:00
2023-01-20 11:42:39 -05:00
// LEVEL
//
2022-12-06 10:57:55 -05:00
// level = 1..4
2023-01-20 11:42:39 -05:00
// level 0 == 0 Volt ==> WET (cannot be overruled).
2022-12-06 10:57:55 -05:00
// level 4 ==> DRY
2022-12-04 11:55:37 -05:00
// user is responsible that values are increasing voltages.
2022-12-06 05:26:48 -05:00
bool setLevel(uint8_t nr, uint16_t milliVolts);
2023-01-20 11:42:39 -05:00
// returns 0..4
2022-12-04 11:55:37 -05:00
uint8_t getLevel();
2023-01-20 11:42:39 -05:00
// POWER
//
// will only work when powerPin is defined in constructor.
2022-12-06 10:57:55 -05:00
void powerOn();
void powerOff();
2023-01-20 11:42:39 -05:00
// for tuning the stabilization delay in powerOn(),
// normally not needed.
void setPowerDelay(uint8_t powerDelay = 100);
uint8_t getPowerDelay();
2022-12-06 10:57:55 -05:00
2022-12-04 11:55:37 -05:00
private:
2023-01-20 11:42:39 -05:00
uint8_t _analogPort;
uint8_t _powerPin = 255; // 255 means not set.
uint8_t _powerDelay = 100; // default
2022-12-04 11:55:37 -05:00
float _maxVoltage;
uint16_t _maxSteps;
2023-01-20 11:42:39 -05:00
float _mVstep = 1;
float _voltage = 0;
2022-12-06 10:57:55 -05:00
float _dryRefVoltage;
2023-01-20 11:42:39 -05:00
float _previous = 0;
2022-12-06 05:26:48 -05:00
uint16_t _level[5] = { 0, 1000, 2000, 3000, 4000 }; // millivolts
2022-12-04 11:55:37 -05:00
};
// -- END OF FILE --