CDS55 Photoresistor
Loading...
Searching...
No Matches
photocell.c File Reference
#include "PhotoCell.h"
#include "stm32f4xx_hal.h"

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.

Variables

ADC_HandleTypeDef hadc1

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.

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.

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.

Variable Documentation

◆ hadc1

ADC_HandleTypeDef hadc1
extern