I am trying to run 2 TCS3200
’s from one Arduino Due
. Next, I must increase to 4 sensors. I need to read the data from the 2 digital pins but how do I read both within the same loop rather than in series to save time. The code reading one sensor tasoOutPin1 (pin 10) works but why can’t I place the second read command int detectColor(int taosOutPin2)
before the {
symbol?
int detectColor(int taosOutPin1) {
float white1 = colorRead(taosOutPin1,0,1);
float red1 = colorRead(taosOutPin1,1,1);
float blue1 = colorRead(taosOutPin1,2,1);
float green1 = colorRead(taosOutPin1,3,1);
}
Thanks,
Scott
-
1What happens when you place the second / third / fourth read in? Why doesn't it work?Peter– Peter2016年09月19日 22:55:53 +00:00Commented Sep 19, 2016 at 22:55
-
Downvoted because you didn't provide enough information for us to help you and you didn't respond to the request for more information.per1234– per12342016年12月20日 03:25:19 +00:00Commented Dec 20, 2016 at 3:25
1 Answer 1
Seems you have to run these serially, but not sure why it's an issue, a due is quick.
seems more programming related... 'detectColor' is a function, and this is run inside the loop i assume.
int taosOutPin1 = 10; //color detector 1
int taosOutPin2 = 2; //Pins are examples, change to actual pin...
int taosOutPin3 = 3;
int taosOutPin4 = 4; //color detector 4
typedef struct {
float white;
float red;
float blue;
float green;
} color;
void setup() {
// put your setup code here, to run once:
}
void loop() {
color detectedColorForSensor1 = detectColor(taosOutPin1);
color detectedColorForSensor2 = detectColor(taosOutPin2);
color detectedColorForSensor3 = detectColor(taosOutPin3);
color detectedColorForSensor4 = detectColor(taosOutPin4);
Serial.print(detectedColorForSensor1.red);
Serial.print(detectedColorForSensor1.green);
Serial.print(detectedColorForSensor1.blue);
Serial.print(detectedColorForSensor1.white);
//etc for sensor 2,3,4............
}
color detectColor(int taosOutPin1) {
color detectedColor;
detectedColor.white = colorRead(taosOutPin1,0,1);
detectedColor.red = colorRead(taosOutPin1,1,1);
detectedColor.blue = colorRead(taosOutPin1,2,1);
detectedColor.green = colorRead(taosOutPin1,3,1);
return detectedColor;
}
Explore related questions
See similar questions with these tags.