@@ -37,6 +37,7 @@ ScienceKitCarrier::ScienceKitCarrier(){
37
37
board_resolution = BOARD_RESOLUTION;
38
38
39
39
apds9960 = new APDS9960 (Wire,INT_APDS9960);
40
+ apds9999 = new Arduino_APDS9999 (Wire);
40
41
proximity=0 ;
41
42
r=0 ;
42
43
g=0 ;
@@ -279,19 +280,48 @@ int ScienceKitCarrier::getInputB(){
279
280
/* *******************************************************************/
280
281
281
282
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
+ }
284
290
}
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
285
304
return 0 ;
286
305
}
287
306
288
307
void ScienceKitCarrier::updateAPDS (){
289
308
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
+ }
292
316
}
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
+ }
295
325
}
296
326
wire_unlock;
297
327
}
0 commit comments