Hi everyone,
I am using a color sensor that has a square signal which varies on frequency as an output. The duty cycle is allways 50%, the freq is the only thing that changes. I need to read two frequency values: 440kHz and 540kHz.
I have read a lot of posts but I have not found a solution. So far I have tried with the "pulseIn" function but it gives me the same frequency for both readings.
Can anyone help me please?
Thanks,
Martin
Ps: I don't know if it matters but the sensor is the TCS3200
int taosOutPin = 11;//pinC
//int LED = 13;//pinD
void setup() {
//pinMode(LED,OUTPUT); //LED pinD
pinMode(taosOutPin, INPUT);
Serial.begin(115200);
Serial.print("\n\n\nready\n\n\n");
delay(100);
}
// primary loop takes color readings from all four channels and displays the raw values once per second.
void loop() {
detectColor(taosOutPin);
Serial.print("\n\n\n");
//delay(1000);
}
int detectColor(int taosOutPin){
float white = colorRead(taosOutPin,0,1);
Serial.print("white ");
Serial.println(white);
}
/*
This section will return the pulseIn reading of the selected color.
taosOutPin is the ouput pin of the TCS3200.
*/
float colorRead(int taosOutPin, int color, boolean LEDstate){
//setting for a delay to let the sensor sit for a moment before taking a reading.
//int sensorDelay = 100;
// create a var where the pulse reading from sensor will go
float readPulse;
// turn LEDs on or off, as directed by the LEDstate var
/*if(LEDstate == 0){
digitalWrite(LED, LOW);
}
if(LEDstate == 1){
digitalWrite(LED, HIGH);
}
*/
// wait a bit for LEDs to actually turn on, as directed by sensorDelay var
//delay(sensorDelay);
// now take a measurement from the sensor, timing a low pulse on the sensor's "out" pin
readPulse = pulseIn(taosOutPin, LOW, 80000);
//if the pulseIn times out, it returns 0 and that throws off numbers. just cap it at 80k if it happens
if(readPulse < .1){
readPulse = 80000;
}
// return the pulse value back to whatever called for it...
return readPulse;
}