35 lines
853 B
C++
35 lines
853 B
C++
#ifndef PHOTORESISTOR_CONTROLLER_H
|
|
#define PHOTORESISTOR_CONTROLLER_H
|
|
|
|
#include <Arduino.h>
|
|
|
|
#define DEFAULT_MIN_READ_INTERVAL 50
|
|
#define DEFAULT_SAMPLES 3
|
|
|
|
class PhotoresistorController {
|
|
private:
|
|
uint8_t _pin;
|
|
unsigned long _lastReadTime;
|
|
unsigned long _minReadInterval;
|
|
int _lastRawValue;
|
|
int _lastPercentValue;
|
|
bool _lastReadSuccess;
|
|
uint8_t _numSamples;
|
|
int _maxValue;
|
|
int _minValue;
|
|
|
|
public:
|
|
PhotoresistorController(uint8_t pin, int minValue = 0, int maxValue = 1023);
|
|
void begin();
|
|
bool read();
|
|
int getRawValue();
|
|
int getPercentValue();
|
|
void calibrate(int minValue, int maxValue);
|
|
void autoCalibrateDark();
|
|
void autoCalibrateBright();
|
|
bool isLastReadSuccessful() const;
|
|
void setMinReadInterval(unsigned long interval);
|
|
void setNumSamples(uint8_t samples);
|
|
};
|
|
|
|
#endif |