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();
}