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

82 lines
1.9 KiB
C
Raw Normal View History

2020-02-17 11:22:11 -05:00
#pragma once
//
// FILE: ML8511.h
// AUTHOR: Rob Tillaart
2022-11-17 14:12:05 -05:00
// VERSION: 0.1.9
2020-02-17 11:22:11 -05:00
// PURPOSE: ML8511 - UV sensor - library for Arduino
2020-11-27 05:20:37 -05:00
// URL: https://github.com/RobTillaart/ML8511
2020-02-17 11:22:11 -05:00
//
2022-11-17 14:12:05 -05:00
// NOTES
// ML8511 is a 3.3 Volt device,
// so do not connect to a 5V device (e.g. UNO)
// this includes the ENABLE PIN !!
2020-02-17 11:22:11 -05:00
//
2022-11-17 14:12:05 -05:00
// +-------+--+
// VIN |o +-+| mounting hole
// 3V3 |o +-+|
// GND |o |
// OUT |o |
// EN |o S | Sensor
// +----------+
2020-02-17 11:22:11 -05:00
2021-04-25 13:56:44 -04:00
2020-02-17 11:22:11 -05:00
#include <Arduino.h>
2022-11-17 14:12:05 -05:00
#define ML8511_LIB_VERSION (F("0.1.9"))
2020-02-17 11:22:11 -05:00
class ML8511
{
public:
2022-11-17 14:12:05 -05:00
// if enablePin is omitted, one must connect EN to 3V3.
2020-11-27 05:20:37 -05:00
ML8511(uint8_t analogPin, uint8_t enablePin = 0xFF);
2020-02-17 11:22:11 -05:00
2022-11-17 14:12:05 -05:00
void reset(); // reset internal variables to initial value.
2021-06-20 03:13:49 -04:00
2022-11-17 14:12:05 -05:00
// energyMode = HIGH or LOW;
// returns mW per cm2
2020-11-27 05:20:37 -05:00
float getUV(uint8_t energyMode = HIGH);
2022-11-17 14:12:05 -05:00
// for external ADC
2021-11-09 14:05:19 -05:00
float voltage2mW(float voltage);
2020-02-17 11:22:11 -05:00
2022-11-17 14:12:05 -05:00
// voltage must be > 0 otherwise it is not set
2020-11-27 05:20:37 -05:00
void setVoltsPerStep(float voltage, uint32_t steps);
2022-11-17 14:12:05 -05:00
float getVoltsPerStep();
2020-11-27 05:20:37 -05:00
2022-11-17 14:12:05 -05:00
// manually enable / disable
2020-11-27 05:20:37 -05:00
void enable();
void disable();
2022-11-17 14:12:05 -05:00
bool isEnabled();
2020-02-17 11:22:11 -05:00
2021-06-20 03:13:49 -04:00
2022-11-17 14:12:05 -05:00
// experimental estimate DUV index
// WARNING: USE WITH CARE
2021-06-20 03:13:49 -04:00
//
2022-11-17 14:12:05 -05:00
// input in mW per cm2 == typical the output of getUV()
2021-06-20 03:13:49 -04:00
float estimateDUVindex(float mWcm2);
2022-11-17 14:12:05 -05:00
// https://github.com/RobTillaart/ML8511/issues/4
// discusses the calibration
// see readme.md how to reverse engineer the factor for
// the estimateDUVindex() conversion function.
// a value of 1.61 was found to be far more accurate
2021-06-20 03:13:49 -04:00
//
2022-11-17 14:12:05 -05:00
// returns false if f < 0.01 (to force positive factor only)
2021-11-09 14:05:19 -05:00
bool setDUVfactor(float factor);
2022-11-17 14:12:05 -05:00
float getDUVfactor();
2021-06-20 03:13:49 -04:00
2020-02-17 11:22:11 -05:00
private:
2020-11-27 05:20:37 -05:00
uint8_t _analogPin;
uint8_t _enablePin;
float _voltsPerStep;
bool _enabled;
2021-06-20 03:13:49 -04:00
float _DUVfactor;
2020-02-17 11:22:11 -05:00
};
2021-05-28 07:39:01 -04:00
2022-11-17 14:12:05 -05:00
// -- END OF FILE --
2021-12-21 14:51:35 -05:00