@@ -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
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+ 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
288307void 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}
0 commit comments