@@ -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 ;
@@ -275,23 +276,57 @@ int ScienceKitCarrier::getInputB(){
275
276
276
277
277
278
/* *******************************************************************/
278
- /* APDS9960 */
279
+ /* APDS99xx */
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
+ apds9999->setGain (APDS9999_GAIN_3X);
295
+ apds9999->setLSResolution (APDS9999_LS_RES_16B);
296
+ apds9999->setLSRate (APDS9999_LS_RATE_25MS);
297
+ color_sensor_used = APDS9999_VERSION;
298
+ }
299
+ #ifdef ESP32
300
+ for (int i=0 ; i<=color_sensor_used; i++){
301
+ digitalWrite (LED_GREEN, LOW);
302
+ delay (100 );
303
+ digitalWrite (LED_GREEN, HIGH);
304
+ delay (100 );
305
+ }
306
+ digitalWrite (LED_GREEN, HIGH);
307
+ #endif
285
308
return 0 ;
286
309
}
287
310
288
311
void ScienceKitCarrier::updateAPDS (){
289
312
wire_lock;
290
- if (apds9960->proximityAvailable ()){
291
- proximity=apds9960->readProximity ();
313
+ if (color_sensor_used==APDS9960_VERSION){
314
+ if (apds9960->proximityAvailable ()){
315
+ proximity=apds9960->readProximity ();
316
+ }
317
+ if (apds9960->colorAvailable ()){
318
+ apds9960->readColor (r,g,b,c);
319
+ }
292
320
}
293
- if (apds9960->colorAvailable ()){
294
- apds9960->readColor (r,g,b,c);
321
+ if (color_sensor_used==APDS9999_VERSION){
322
+ r = apds9999->getRed ()*4097 /65535.0 ;
323
+ g = apds9999->getGreen ()*4097 /262144.0 ;
324
+ b = apds9999->getBlue ()*4097 /131072.0 ;
325
+ c = apds9999->getIR ()*4097 /4096.0 ;
326
+ proximity = 255 - apds9999->getProximity ();
327
+ if (proximity>255 ){
328
+ proximity = 0 ;
329
+ }
295
330
}
296
331
wire_unlock;
297
332
}
@@ -778,7 +813,7 @@ void ScienceKitCarrier::retriveUltrasonicUpdate(){
778
813
}
779
814
780
815
float ScienceKitCarrier::getDistance (){
781
- return distance;
816
+ return distance/ 1000.0 ;
782
817
}
783
818
784
819
float ScienceKitCarrier::getTravelTime (){
0 commit comments