Forum >Replies by denorro
userhead denorro
Replies (2)
  • You Reply: Micro pins C0 and C1 connect  sensor's S0 and S1 are the pins on the color sensor to setup of the scale factor (in my case 2%)

    Micro pin B3 is connected to the led pin  on the sensor

    Micro pins D0 and D1 is connected to pin S2,S3 on the color sensor that I'm using to set the filters.
    (r,g,b,clear filters)

    micro pin D2 is the output pin from the color sensor that sends the data back to the micro.

    The get_last_high_pulse returns the duration of the high pulse from that square wave and enclose it in pulse_to_microseconds to convert that time in microseconds otherwise it will give me the time in multiples of 0.04 microseconds.
  • You Reply: Am I using this color sensor right? I measuring the duration of the output square wave that is outputted from the sensor. Using that duration I am calculating frequency. I am getting consistent values for objects that are very close. I would I go about measuring objects that aren't that far away but the surrounding light does have an effect on the square wave duration readings. How can I measure the surrounding light and use that to almost get the same values as when there was no light as when the object was very close?

    PLEASE DO SHARE YOUR THOUGHTS! ALL ARE WELCOME!

    Here is my code:
    Code: Select all
    //unsigned long sum = 0;
    	unsigned long red = 0;
    	unsigned long green = 0;
    	unsigned long blue = 0;
    	unsigned long Clear = 0;
    	set_digital_output(IO_C0,LOW);
    	set_digital_output(IO_C1,HIGH);
    	set_digital_input(IO_D2,PULL_UP_ENABLED);
    	pulse_in_start((unsigned char[]){IO_D2},1);
    		
    	while(1){
    		
    		ledOn();
    		if(new_high_pulse(0)){
    			
    		set_digital_output(IO_D0,HIGH); // clear filter
    		set_digital_output(IO_D1,HIGH); // clear filter
    		delay(10);
    		Clear = pulse_to_microseconds(get_last_high_pulse(0)); // get the length of pulse of clear
    		int clearFreq = (1 / (2 * (Clear * 0.000001)));  //converts the duration to microseconds and f = 1 / 2*T
    				
    		set_digital_output(IO_D0,LOW); // RED FILTER
    		set_digital_output(IO_D1,LOW); // RED FILTER	
    		delay(10);
    		red = pulse_to_microseconds(get_last_high_pulse(0)); // get the length of pulse of red
    		int redFreq = (1 / (2 * (red * 0.000001)));
    		
    		set_digital_output(IO_D0,HIGH); // GREEN FILTER
    		set_digital_output(IO_D1,HIGH); // GREEN FILTER
    		delay(10);
    		green = pulse_to_microseconds(get_last_high_pulse(0));
    		int greenFreq = (1 / (2 * (green * 0.000001)));
    		
    		set_digital_output(IO_D0,LOW); // BLUE FILTER
    		set_digital_output(IO_D1,HIGH); // BLUE FILTER
    		delay(10);
    		blue = pulse_to_microseconds(get_last_high_pulse(0));
    		int blueFreq = (1 / (2 * (blue * 0.000001)));	
    		
    		print("r:");
    		print_long(red);
    		lcd_goto_xy(8,0);
    		print("g:");
    		print_long(green);
    		lcd_goto_xy(0,1);
    		print("b:");
    		print_long(blue);
    		lcd_goto_xy(8,1);
    		print("c:");
    		print_long(Clear);
    		delay(2000);
    		clear();
    		
    		//print("r:");
    		print_long(redFreq);
    		lcd_goto_xy(8,0);
    		//print("g:");
    		print_long(greenFreq);
    		lcd_goto_xy(0,1);
    		//print("b:");
    		print_long(blueFreq);
    		lcd_goto_xy(8,1);
    		//print("c:");
    		print_long(clearFreq);
    		delay(2000);
    		clear();
    			
    		}