Skip to content

Commit 8707188

Browse files
committed
add: apds9999 support
1 parent 7fbb03b commit 8707188

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

src/Arduino_ScienceKitCarrier.cpp

+36-6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ ScienceKitCarrier::ScienceKitCarrier(){
3737
board_resolution = BOARD_RESOLUTION;
3838

3939
apds9960 = new APDS9960(Wire,INT_APDS9960);
40+
apds9999 = new Arduino_APDS9999(Wire);
4041
proximity=0;
4142
r=0;
4243
g=0;
@@ -279,19 +280,48 @@ int ScienceKitCarrier::getInputB(){
279280
/********************************************************************/
280281

281282
int ScienceKitCarrier::beginAPDS(){
282-
if (!apds9960->begin()) {
283-
return ERR_BEGIN_APDS;
283+
if (!apds9999->begin()){
284+
if (!apds9960->begin()) {
285+
return ERR_BEGIN_APDS;
286+
}
287+
else{
288+
color_sensor_used = APDS9960_VERSION;
289+
}
284290
}
291+
else{
292+
apds9999->enableColorSensor();
293+
apds9999->enableProximitySensor();
294+
color_sensor_used = APDS9999_VERSION;
295+
}
296+
#ifdef ESP32
297+
for(int i=0; i<=color_sensor_used; i++){
298+
analogWrite(LED_GREEN,64);
299+
delay(100);
300+
digitalWrite(LED_GREEN,HIGH);
301+
delay(100);
302+
}
303+
#endif
285304
return 0;
286305
}
287306

288307
void ScienceKitCarrier::updateAPDS(){
289308
wire_lock;
290-
if (apds9960->proximityAvailable()){
291-
proximity=apds9960->readProximity();
309+
if (color_sensor_used==APDS9960_VERSION){
310+
if (apds9960->proximityAvailable()){
311+
proximity=apds9960->readProximity();
312+
}
313+
if (apds9960->colorAvailable()){
314+
apds9960->readColor(r,g,b,c);
315+
}
292316
}
293-
if (apds9960->colorAvailable()){
294-
apds9960->readColor(r,g,b,c);
317+
if (color_sensor_used==APDS9999_VERSION){
318+
r = apds9999->getRed()>>1;
319+
g = apds9999->getGreen()>>1;
320+
b = apds9999->getBlue()>>1;
321+
proximity = 255 - apds9999->getProximity();
322+
if (proximity>255){
323+
proximity = 0;
324+
}
295325
}
296326
wire_unlock;
297327
}

src/Arduino_ScienceKitCarrier.h

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
#include <Wire.h>
3333
#include "Arduino_APDS9960.h"
34+
#include "Arduino_APDS9999.h"
3435
#include "INA.h"
3536

3637
#include "bsec2.h"
@@ -75,7 +76,9 @@ class ScienceKitCarrier{
7576
uint8_t timer_inputA;
7677

7778
APDS9960 * apds9960;
79+
Arduino_APDS9999 * apds9999;
7880
int r,g,b,c, proximity;
81+
int color_sensor_used;
7982

8083
INA_Class * ina;
8184
float voltage, current;

src/utils/Arduino_ScienceKitCarrier_definitions.h

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
// APDS9960
3939
#define INT_APDS9960 9
40+
#define APDS9960_VERSION 0
41+
#define APDS9999_VERSION 1
4042

4143
// INA
4244
const uint32_t SHUNT_MICRO_OHM{100000}; // check schematic R20

0 commit comments

Comments
 (0)