From 5ce29a28ead5a2440d207dc05b1872b1c58b0756 Mon Sep 17 00:00:00 2001
From: Thomas VADEBOUT <thomas.vadebout@insa-lyon.fr>
Date: Tue, 29 Jun 2021 00:11:46 +0000
Subject: [PATCH] add integral time divider and add spinOnce

---
 src/Adafruit_TCS34725.cpp | 17 +++++++++++------
 src/main.cpp              |  1 +
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/Adafruit_TCS34725.cpp b/src/Adafruit_TCS34725.cpp
index 4438113..bb3a9e8 100644
--- a/src/Adafruit_TCS34725.cpp
+++ b/src/Adafruit_TCS34725.cpp
@@ -24,6 +24,10 @@
 
 #define ARDUINO 200
 
+// allow to divide delay time by this factor. Put the number of sensor here. 
+// todo : make a better fix that don't use delay anymore.
+#define INTEG_DIVIDER 2
+
 #include <math.h>
 #include <stdlib.h>
 
@@ -285,25 +289,26 @@ void Adafruit_TCS34725::getRawData(uint16_t *r, uint16_t *g, uint16_t *b,
   *g = read16(TCS34725_GDATAL);
   *b = read16(TCS34725_BDATAL);
 
+
   /* Set a delay for the integration time */
   switch (_tcs34725IntegrationTime) {
   case TCS34725_INTEGRATIONTIME_2_4MS:
-    delay(3);
+    delay((3/INTEG_DIVIDER) + 1);
     break;
   case TCS34725_INTEGRATIONTIME_24MS:
-    delay(24);
+    delay((24/INTEG_DIVIDER) + 1);
     break;
   case TCS34725_INTEGRATIONTIME_50MS:
-    delay(50);
+    delay((50/INTEG_DIVIDER) + 1);
     break;
   case TCS34725_INTEGRATIONTIME_101MS:
-    delay(101);
+    delay((101/INTEG_DIVIDER) + 1);
     break;
   case TCS34725_INTEGRATIONTIME_154MS:
-    delay(154);
+    delay((154/INTEG_DIVIDER) + 1);
     break;
   case TCS34725_INTEGRATIONTIME_700MS:
-    delay(700);
+    delay((700/INTEG_DIVIDER) + 1);
     break;
   }
 }
diff --git a/src/main.cpp b/src/main.cpp
index 3815bf4..eec42ad 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -339,6 +339,7 @@ void colorSensorsLoop(){
   hsv_msg.z = v;
 
   color_sensor_right.publish( &hsv_msg );
+  nh.spinOnce();
 }
 
 void loop()
-- 
GitLab