GY-63_MS5611/libraries/Max44009/examples/max44009_setManualMode/max44009_setManualMode.ino

78 lines
1.3 KiB
Arduino
Raw Normal View History

//
// FILE: max44009_setManualMode.ino
// AUTHOR: Rob Tillaart
2021-05-28 07:37:15 -04:00
// VERSION: 0.1.1
// PURPOSE: demo of max44009 library
// DATE: 2020-01-30
//
// Released to the public domain
//
2021-05-28 07:37:15 -04:00
#include "Wire.h"
#include "Max44009.h"
Max44009 myLux(0x4A);
uint32_t lastDisplay = 0;
uint32_t lastChangeCDRTIM = 0;
uint8_t CDR = 0;
uint8_t TIM = 0;
2021-05-28 07:37:15 -04:00
void setup()
{
Serial.begin(115200);
Serial.print("\nStart max44009_setManualMode : ");
Serial.println(MAX44009_LIB_VERSION);
Wire.begin();
myLux.setManualMode(CDR, TIM);
}
2021-05-28 07:37:15 -04:00
void loop()
{
uint32_t interval = 100;
if (millis() - lastDisplay >= interval)
{
lastDisplay += interval;
float lux = myLux.getLux();
int err = myLux.getError();
if (err != 0)
{
Serial.print("Error:\t");
Serial.println(err);
}
else
{
Serial.print("lux:\t");
Serial.println(lux);
}
}
// Change CDR and TIM every 5 seconds
// Note that the value of getLux() is affected
// for up to about a second.
if (millis() - lastChangeCDRTIM >= 5000)
{
lastChangeCDRTIM += 5000;
2021-05-28 07:37:15 -04:00
TIM++;
if (TIM == 4)
{
TIM = 0;
CDR = (CDR + 1) & 1;
}
myLux.setManualMode(CDR, TIM);
2021-05-28 07:37:15 -04:00
Serial.print("CDR:\t");
Serial.print((int)CDR);
Serial.print("\tTIM:\t");
Serial.println((int)TIM);
}
}
2021-05-28 07:37:15 -04:00
// END OF FILE