mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.5.2 MAX44009
This commit is contained in:
parent
a9d160c97a
commit
a2ab58e222
@ -2,7 +2,7 @@
|
||||
|
||||
// FILE: Max44009.h
|
||||
// AUTHOR: Rob dot Tillaart at gmail dot com
|
||||
// VERSION: 0.5.1
|
||||
// VERSION: 0.5.2
|
||||
// PURPOSE: library for MAX44009 lux sensor Arduino
|
||||
// HISTORY: See Max440099.cpp
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
|
||||
#define MAX44009_LIB_VERSION (F("0.5.1"))
|
||||
#define MAX44009_LIB_VERSION (F("0.5.2"))
|
||||
|
||||
#define MAX44009_DEFAULT_ADDRESS 0x4A
|
||||
#define MAX44009_ALT_ADDRESS 0x4B
|
||||
@ -123,7 +123,7 @@ public:
|
||||
float convertToLux(uint8_t datahigh, uint8_t datalow);
|
||||
|
||||
|
||||
private:
|
||||
protected:
|
||||
bool setThreshold(uint8_t reg, float value);
|
||||
float getThreshold(uint8_t reg);
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/Max44009.git"
|
||||
},
|
||||
"version": "0.5.1",
|
||||
"version": "0.5.2",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=Max44009
|
||||
version=0.5.1
|
||||
version=0.5.2
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library for MAX44009 I2C LUX sensor Arduino.
|
||||
|
@ -1,18 +1,19 @@
|
||||
//
|
||||
// FILE: Max44009.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.5.1
|
||||
// VERSION: 0.5.2
|
||||
// PURPOSE: library for MAX44009 lux sensor Arduino
|
||||
// URL: https://github.com/RobTillaart/MAX44009
|
||||
//
|
||||
// HISTORY
|
||||
//
|
||||
// 0.5.2 2022-01-05 minor edits after creating Max44007 library
|
||||
// 0.5.1 2021-12-21 update library.json, license, minor edits
|
||||
// 0.5.0 2021-06-04 fix exponent math.
|
||||
// 0.4.4 2021-05-27 arduino-lint
|
||||
// 0.4.3 2020-12-30 arduino-ci, unit test
|
||||
// 0.4.4 2021-05-27 Arduino-lint
|
||||
// 0.4.3 2020-12-30 Arduino-CI, unit test
|
||||
// 0.4.2 2020-06-19 fix library.json
|
||||
// 0.4.1 2020-03-21 #pragma, readme.nd, license.md
|
||||
// 0.4.1 2020-03-21 #pragma, readme.md, license.md
|
||||
// 0.4.0 2020-01-30 remove automatic mode from constructors;
|
||||
// added example code
|
||||
// 0.3.3 2020-01-27 issue #140 refactor constructors / configure
|
||||
@ -40,6 +41,10 @@
|
||||
|
||||
#include "Max44009.h"
|
||||
|
||||
// MAX44007 KEY VALUES
|
||||
#define MAX44009_MIN_LUX (0.045)
|
||||
#define MAX44009_MAX_LUX (188006.0)
|
||||
|
||||
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
Max44009::Max44009(const uint8_t address, const uint8_t dataPin, const uint8_t clockPin)
|
||||
@ -216,7 +221,7 @@ float Max44009::convertToLux(uint8_t datahigh, uint8_t datalow)
|
||||
{
|
||||
uint8_t exponent = datahigh >> 4;
|
||||
uint32_t mantissa = ((datahigh & 0x0F) << 4) + (datalow & 0x0F);
|
||||
float lux = ((0x0001 << exponent) * 0.045) * mantissa;
|
||||
float lux = ((0x0001 << exponent) * MAX44009_MIN_LUX) * mantissa;
|
||||
return lux;
|
||||
}
|
||||
|
||||
@ -228,9 +233,9 @@ float Max44009::convertToLux(uint8_t datahigh, uint8_t datalow)
|
||||
bool Max44009::setThreshold(const uint8_t reg, const float value)
|
||||
{
|
||||
// CHECK RANGE OF VALUE
|
||||
if ((value < 0.0) || (value > 188006)) return false;
|
||||
if ((value < 0.0) || (value > MAX44009_MAX_LUX)) return false;
|
||||
|
||||
uint32_t mantissa = round(value * 22.2222222); // was round(value / 0.045); multiply is faster.
|
||||
uint32_t mantissa = round(value * (1.0 / MAX44009_MIN_LUX)); // compile time optimized.
|
||||
uint8_t exponent = 0;
|
||||
while (mantissa > 255)
|
||||
{
|
||||
|
@ -18,6 +18,8 @@ a.k.a. GY-49
|
||||
The MAX44009 ambient light sensor is an I2C sensor, that has a 22 bit
|
||||
dynamic range from 0.045 lux to 188,000 lux.
|
||||
|
||||
relates to https://github.com/RobTillaart/Max44007
|
||||
|
||||
|
||||
## Schema breakout max44009 / GY-49
|
||||
|
||||
@ -176,5 +178,10 @@ right address and sometimes not. (been there ;)
|
||||
## Future
|
||||
|
||||
- improve documentation
|
||||
-
|
||||
- merge MAX44007 library in the future. (shared base class?)
|
||||
|
||||
|
||||
#### MAX44007
|
||||
|
||||
The MAX44007 is an almost identical sensor that uses a step size of 0.025.
|
||||
That implies the library is not useable 1 to 1 for the MAX4007, however some
|
||||
|
Loading…
Reference in New Issue
Block a user