add basic PT Reading

This commit is contained in:
hhaupt
2024-04-26 14:58:20 +02:00
parent dbe97dc94c
commit 1d074f26d1
4 changed files with 83 additions and 54 deletions

View File

@@ -1,8 +1,83 @@
/**
* @file LightDetection.h
* @author Hans Haupt (hans.haupt@dezibot.de)
* @brief Class for Reading the values of the different Phototransistors, both IR, and DaylightSensors are supported.
* @version 0.1
* @date 2024-04-26
*
* @copyright Copyright (c) 2024
*
*/
#ifndef LightDetection_h
#define LightDetection_h
#include <stdint.h>
#include <Arduino.h>
enum photoTransistors{
IR_LEFT,
IR_RIGHT,
IR_FRONT,
IR_BACK,
DL_FRONT,
DL_BOTTOM
};
enum ptType{
IR,
DAYLIGHT
};
//beinhaltet IR + Tageslicht
class LightDetection{
public:
/**
* @brief initialize the Lightdetection Compnent, must be called before the other methods are used.
*
*/
void begin(void);
/**
* @brief reads the Value of the specified sensor
*
* @param sensor which sensor to read
* @return uint the reading of the sensor. between 0-4095
*/
uint16_t getValue(photoTransistors sensor);
/**
* @brief can be used to determine which sensor is exposed to the greatest amount of light
* Can distingish between IR and Daylight
*
* @param type select which PTTransistors to compare
* @return photoTransistors which sensor is exposed to the greatest amount of light
*/
photoTransistors getBrightest(ptType type);
/**
* @brief Get the Average of multiple measurments of a single PT
*
* @param sensor Which Phototransistor should be read
* @param measurments how many measurements should be taken
* @param timeBetween which time should elapse between
* @return the average of all taken meaurments
*/
uint32_t getAverageValue(photoTransistors sensor, uint32_t measurments, uint32_t timeBetween);
protected:
static const uint8_t IR_PT_FRONT_ADC = 3;
static const uint8_t IR_PT_LEFT_ADC = 4;
static const uint8_t IR_PT_RIGHT_ADC = 5;
static const uint8_t IR_PT_BACK_ADC = 6;
static const uint8_t DL_PT_FRONT_ADC = 7;
static const uint8_t DL_PT_BOTTOM_ADC = 8;
static const uint8_t DL_PT_ENABLE = 41;
static const uint8_t IR_PT_ENABLE = 40;
void beginInfrared(void);
void beginDaylight(void);
uint16_t readIRPT(photoTransistors sensor);
uint16_t readDLPT(photoTransistors sensor);
};
#endif //LightDetection_h