CDS55 Photoresistor
Loading...
Searching...
No Matches
photocell.h File Reference
#include <stdint.h>
#include <stdbool.h>

Go to the source code of this file.

Classes

struct  photoCell_t

Macros

#define DEFAULT_SCALING   true
#define DEFAULT_MIN_READ   0
#define DEFAULT_MAX_READ   4095

Functions

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.
uint8_t readSensor (photoCell_t *sensor)
 Reads the photocell value from ADC and updates the sensor state.

Macro Definition Documentation

◆ DEFAULT_MAX_READ

#define DEFAULT_MAX_READ   4095

◆ DEFAULT_MIN_READ

#define DEFAULT_MIN_READ   0

◆ DEFAULT_SCALING

#define DEFAULT_SCALING   true

Function Documentation

◆ 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
sensorPointer to photoCell_t struct to initialize.
scaledWhether to enable scaled output (0–100).
min_valueMinimum raw value from the ADC.
max_valueMaximum 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
sensorPointer to a photoCell_t instance to initialize.
scaledIf true, the output will be scaled to a range of 0–100.
min_valueMinimum expected raw ADC value for scaling.
max_valueMaximum expected raw ADC value for scaling.

◆ readSensor()

uint8_t readSensor ( photoCell_t * sensor)

Reads the photocell value from ADC and updates the sensor state.

Reads the photocell sensor and updates current_level and last_raw_value.

Parameters
sensorPointer to photoCell_t struct.
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
sensorPointer to a photoCell_t instance to update.
Returns
uint8_t Scaled (0–100) or raw (0–255 clipped) light level.