ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
APDS9960.cpp
Go to the documentation of this file.
1#include "APDS9960.h"
2
3Adafruit_APDS9960 APDS9960::apds;
6
9float APDS9960::minimum = 0.0f;
10bool APDS9960::didBegin = false;
11bool APDS9960::isBright = false;
12bool APDS9960::isProx = false;
13
14bool APDS9960::Initialize(uint8_t threshold) {
16
17 Wire.setClock(100000); // for longer-range transmissions
18 Wire.begin();
19
20#ifdef WS35
21 Wire.setSDA(19);
22 Wire.setSCL(18);
23#else
24 Wire.setSDA(18);
25 Wire.setSCL(19);
26#endif
27
28 Wire.beginTransmission(0x39);
29 uint8_t error = Wire.endTransmission();
30
31 if (error == 0) { // SSD1306 Found
32 didBegin = apds.begin();
33
34 // apds.setLED(APDS9960_LEDDRIVE_12MA, APDS9960_LEDBOOST_100PCNT);
35 // apds.setProxGain(APDS9960_PGAIN_1X);
36 } else {
37 didBegin = false;
38 }
39
40 return didBegin;
41}
42
44 GetValue();
45
46 if (timeStep.IsReady()) {
48 }
49
50 return proximity > minimum + threshold;
51}
52
54 Wire.end(); // Disable the I2C hardware
55 delay(10); // Wait a bit
56 Wire.begin(); // Re-enable the I2C hardware
57}
58
60 unsigned long cmdTime = millis();
61
62 if (didBegin) {
63 if (!isProx) {
64 apds.enableProximity(true);
65 isProx = true;
66 }
67 proximity = apds.readProximity();
68 }
69
70 if (millis() - cmdTime > 100) {
71 // Timeout occurred
73 }
74
75 return proximity;
76}
77
79 uint16_t brightness;
80 uint16_t r, g, b, c;
81
82 if (didBegin) {
83 if (!isBright) {
84 apds.enableColor();
85 isBright = true;
86 }
87
88 apds.getColorData(&r, &g, &b, &c);
89
90 brightness = r + g + b + c;
91 }
92 else{
93 brightness = 0;
94 }
95
96 return brightness;
97}
A class for interfacing with the Adafruit APDS9960 sensor.
static bool isProx
Flag indicating if proximity detection is enabled.
Definition APDS9960.h:37
static uint16_t GetBrightness()
Retrieves the current brightness value.
Definition APDS9960.cpp:78
static float minimum
Minimum detected value.
Definition APDS9960.h:34
static MinFilter< 10 > minF
Minimum filter for smoothing proximity values.
Definition APDS9960.h:32
static bool isBright
Flag indicating if brightness detection is enabled.
Definition APDS9960.h:36
static bool Initialize(uint8_t threshold)
Initializes the APDS9960 sensor.
Definition APDS9960.cpp:14
static bool isBooped()
Checks if the sensor is "booped" (close proximity detected).
Definition APDS9960.cpp:43
static TimeStep timeStep
Time utility for managing timing intervals.
Definition APDS9960.h:33
static uint8_t GetValue()
Retrieves the current proximity value.
Definition APDS9960.cpp:59
static uint16_t proximity
Current proximity value.
Definition APDS9960.h:30
static Adafruit_APDS9960 apds
Instance of the Adafruit APDS9960 sensor.
Definition APDS9960.h:29
static uint16_t threshold
Threshold value for proximity detection.
Definition APDS9960.h:31
static void ResetI2CBus()
Resets the I2C bus in case of communication issues.
Definition APDS9960.cpp:53
static bool didBegin
Flag indicating if the sensor has been initialized.
Definition APDS9960.h:35
Implements a minimum filter over a sliding window.
Definition MinFilter.h:28
float Filter(float value)
Filters the given value, updating the minimum value within the memory window.
Provides a mechanism to trigger actions at a specified frequency.
Definition TimeStep.h:18
bool IsReady()
Checks if the specified time interval has elapsed.
Definition TimeStep.cpp:11