@@ -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 ;
@@ -275,23 +276,57 @@ int ScienceKitCarrier::getInputB(){
275276
276277
277278/* *******************************************************************/
278- /* APDS9960 */
279+ /* APDS99xx */
279280/* *******************************************************************/
280281
281282int 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+ 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
285308 return 0 ;
286309}
287310
288311void ScienceKitCarrier::updateAPDS (){
289312 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+ }
292320 }
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+ }
295330 }
296331 wire_unlock;
297332}
@@ -778,7 +813,7 @@ void ScienceKitCarrier::retriveUltrasonicUpdate(){
778813}
779814
780815float ScienceKitCarrier::getDistance (){
781- return distance;
816+ return distance/ 1000.0 ;
782817}
783818
784819float ScienceKitCarrier::getTravelTime (){
0 commit comments