mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
Fix issue #127 - ctor
small optimization in setThreshold() add Wire.begin() to setup() of example sketch
This commit is contained in:
parent
d68ca6b43a
commit
169bb2e42f
@ -3,7 +3,7 @@
|
||||
//
|
||||
// FILE: Max44009.h
|
||||
// AUTHOR: Rob dot Tillaart at gmail dot com
|
||||
// VERSION: 0.1.10
|
||||
// VERSION: 0.2.0
|
||||
// PURPOSE: library for MAX44009 lux sensor Arduino
|
||||
// HISTORY: See Max440099.cpp
|
||||
//
|
||||
@ -18,7 +18,7 @@
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#define MAX44009_LIB_VERSION "0.1.10"
|
||||
#define MAX44009_LIB_VERSION "0.2.0"
|
||||
|
||||
// REGISTERS
|
||||
#define MAX44009_INTERRUPT_STATUS 0x00
|
||||
@ -40,9 +40,13 @@
|
||||
class Max44009
|
||||
{
|
||||
public:
|
||||
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
// dataPin and clockPin can be used for ESP8266
|
||||
// for UNO ignore these (and its warning)
|
||||
Max44009(const uint8_t address, const uint8_t dataPin = 255, const uint8_t clockPin = 255);
|
||||
Max44009(const uint8_t address, const uint8_t dataPin, const uint8_t clockPin);
|
||||
#endif
|
||||
// ctor for UNO
|
||||
Max44009(const uint8_t address);
|
||||
|
||||
float getLux();
|
||||
int getError();
|
||||
|
@ -1,10 +1,9 @@
|
||||
//
|
||||
// FILE: max44009_test01.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// VERSION: 0.1.2
|
||||
// PURPOSE: demo of max44009 library
|
||||
// DATE: 2015-08-06
|
||||
// URL: ?
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
@ -12,7 +11,7 @@
|
||||
#include "Wire.h"
|
||||
#include "Max44009.h"
|
||||
|
||||
Max44009 myLux(0xCB); // default addr
|
||||
Max44009 myLux(0xCB); // default addr
|
||||
|
||||
uint32_t lastDisplay = 0;
|
||||
|
||||
@ -21,6 +20,9 @@ void setup()
|
||||
Serial.begin(115200);
|
||||
Serial.print("Start max44009_test01 : ");
|
||||
Serial.println(MAX44009_LIB_VERSION);
|
||||
|
||||
Wire.begin();
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
@ -44,4 +46,4 @@ void loop()
|
||||
|
||||
}
|
||||
|
||||
|
||||
// END OF FILE
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/Arduino.git"
|
||||
},
|
||||
"version":"0.1.10",
|
||||
"version":"0.2.0",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"export": {
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=Max44009
|
||||
version=0.1.10
|
||||
version=0.2.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library for MAX44009 lux sensor Arduino.
|
||||
|
@ -1,12 +1,13 @@
|
||||
//
|
||||
// FILE: Max44009.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.10
|
||||
// VERSION: 0.2.0
|
||||
// PURPOSE: library for MAX44009 lux sensor Arduino
|
||||
// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
// 0.2.0 - 2019-08-23 solve #127 == redo #118
|
||||
// 0.1.10 - 2018-12-08 issue #118 Fix constructor esp8266
|
||||
// (thanks to Bolukan)
|
||||
// 0.1.9 - 2018-07-01 issue #108 Fix shift math
|
||||
@ -24,10 +25,13 @@
|
||||
|
||||
#include "Max44009.h"
|
||||
|
||||
|
||||
#if defined(ESP8266) || defined(ESP32)
|
||||
Max44009::Max44009(const uint8_t address, const uint8_t dataPin, const uint8_t clockPin)
|
||||
{
|
||||
_address = address;
|
||||
_data = 0;
|
||||
_error = 0;
|
||||
|
||||
if ((dataPin < 255) && (clockPin < 255))
|
||||
{
|
||||
Wire.begin(dataPin, clockPin);
|
||||
@ -35,8 +39,17 @@ Max44009::Max44009(const uint8_t address, const uint8_t dataPin, const uint8_t c
|
||||
Wire.begin();
|
||||
}
|
||||
// TWBR = 12; // Wire.setClock(400000);
|
||||
}
|
||||
#endif
|
||||
|
||||
Max44009::Max44009(const uint8_t address)
|
||||
{
|
||||
_address = address;
|
||||
_data = 0;
|
||||
_error = 0;
|
||||
|
||||
Wire.begin();
|
||||
// TWBR = 12; // Wire.setClock(400000);
|
||||
}
|
||||
|
||||
float Max44009::getLux(void)
|
||||
@ -132,7 +145,7 @@ void Max44009::setManualMode(uint8_t CDR, uint8_t TIM)
|
||||
void Max44009::setThreshold(const uint8_t reg, const float value)
|
||||
{
|
||||
// TODO CHECK RANGE
|
||||
uint32_t m = round(value / 0.045); // mulitply * 22.22222222 is faster.
|
||||
uint32_t m = round(value * 22.2222222); // was round(value / 0.045); mulitply is faster.
|
||||
uint8_t e = 0;
|
||||
while (m > 255)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user