#include <stdint.h>
#include <stdbool.h>
Go to the source code of this file.
◆ DEFAULT_MAX_READ
#define DEFAULT_MAX_READ 4095 |
◆ DEFAULT_MIN_READ
#define DEFAULT_MIN_READ 0 |
◆ DEFAULT_SCALING
#define DEFAULT_SCALING true |
◆ photoCell_init()
void photoCell_init |
( |
photoCell_t * | sensor, |
|
|
bool | scaled, |
|
|
uint16_t | min_value, |
|
|
uint16_t | max_value ) |
Initializes a photoCell_t instance with the specified configuration.
Initializes the photocell with default or custom values.
- Parameters
-
sensor | Pointer to photoCell_t struct to initialize. |
scaled | Whether to enable scaled output (0–100). |
min_value | Minimum raw value from the ADC. |
max_value | Maximum raw value from the ADC. |
This function sets the scaling behavior and raw ADC min/max calibration points. It also clears the current light level and last raw ADC value.
- Parameters
-
sensor | Pointer to a photoCell_t instance to initialize. |
scaled | If true, the output will be scaled to a range of 0–100. |
min_value | Minimum expected raw ADC value for scaling. |
max_value | Maximum expected raw ADC value for scaling. |
◆ readSensor()
Reads the photocell value from ADC and updates the sensor state.
Reads the photocell sensor and updates current_level and last_raw_value.
- Parameters
-
- Returns
- Scaled light level (0–100 if scaled, or raw clipped to 0–255).
This function performs a blocking ADC read using STM32 HAL and stores both the raw and optionally scaled light level into the provided sensor instance.
- Parameters
-
- Returns
- uint8_t Scaled (0–100) or raw (0–255 clipped) light level.