diff --git a/libraries/Max44009/Max44009.h b/libraries/Max44009/Max44009.h index 1e6ba37c..433d4188 100644 --- a/libraries/Max44009/Max44009.h +++ b/libraries/Max44009/Max44009.h @@ -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); diff --git a/libraries/Max44009/library.json b/libraries/Max44009/library.json index d62c2bc9..7e4811e9 100644 --- a/libraries/Max44009/library.json +++ b/libraries/Max44009/library.json @@ -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": "*", diff --git a/libraries/Max44009/library.properties b/libraries/Max44009/library.properties index fbe0b506..c74df425 100644 --- a/libraries/Max44009/library.properties +++ b/libraries/Max44009/library.properties @@ -1,5 +1,5 @@ name=Max44009 -version=0.5.1 +version=0.5.2 author=Rob Tillaart maintainer=Rob Tillaart sentence=Library for MAX44009 I2C LUX sensor Arduino. diff --git a/libraries/Max44009/max44009.cpp b/libraries/Max44009/max44009.cpp index f72e30f5..ec4cd237 100644 --- a/libraries/Max44009/max44009.cpp +++ b/libraries/Max44009/max44009.cpp @@ -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) { diff --git a/libraries/Max44009/readme.md b/libraries/Max44009/readme.md index 351a6cf4..ef6c976c 100644 --- a/libraries/Max44009/readme.md +++ b/libraries/Max44009/readme.md @@ -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