CDS55 Photoresistor
Loading...
Searching...
No Matches
photocell.h
Go to the documentation of this file.
1#pragma once
2#include <stdint.h>
3#include <stdbool.h>
4
5// Default configuration macros (raw ADC range for 12-bit)
6#define DEFAULT_SCALING true
7#define DEFAULT_MIN_READ 0
8#define DEFAULT_MAX_READ 4095
9
10typedef struct {
11 bool scaled; // Whether to scale result to 0–100
12 uint16_t min_value; // Raw ADC value mapped to "0%"
13 uint16_t max_value; // Raw ADC value mapped to "100%"
14 uint8_t current_level; // Scaled result (0–100 or 0–255)
15 uint16_t last_raw_value; // Most recent raw ADC value
17
25void photoCell_init(photoCell_t* sensor, bool scaled, uint16_t min_value, uint16_t max_value);
26
32uint8_t readSensor(photoCell_t* sensor);
uint8_t readSensor(photoCell_t *sensor)
Reads the photocell value from ADC and updates the sensor state.
Definition photocell.c:51
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.
Definition photocell.c:34
Definition photocell.h:10
uint8_t current_level
Definition photocell.h:14
uint16_t min_value
Definition photocell.h:12
uint16_t max_value
Definition photocell.h:13
uint16_t last_raw_value
Definition photocell.h:15
bool scaled
Definition photocell.h:11