// Color Sensor Demonstration Program // by Michael Gasperi #define COLOR SENSOR_1 //color sensor on sensor port 1 #define SHORT_WAIT 2 //short wait for value to stabilize int hue; //hue as a global task main() int r,g,b,max,min,d,rd,gd,bd,h; //declare all other variables SetUserDisplay (hue,0); //set display to show hue value SetSensor(COLOR, SENSOR_LIGHT); //power on sensor by making it light type while (true) //loop forever { while (COLOR != 100) //only mux channel 0 will read 100 { SetSensor(COLOR, SENSOR_TOUCH);//power off sensor by making touch SetSensor(COLOR, SENSOR_LIGHT);//reapply power to toggle channel Wait(SHORT_WAIT); //wait for reading to stabilize PlaySound(SOUND_LOW_BEEP); //alarm sound } SetSensor(COLOR, SENSOR_TOUCH); //toggle power to change to channel 1 SetSensor(COLOR, SENSOR_LIGHT); Wait(SHORT_WAIT); r = COLOR*100; //read the red and scale by 100 SetSensor(COLOR, SENSOR_TOUCH); //toggle power to change to channel 2 SetSensor(COLOR, SENSOR_LIGHT); Wait(SHORT_WAIT); g = COLOR*100; //read the green and scale by 100 SetSensor(COLOR, SENSOR_TOUCH); //toggle power to change to channel 3 SetSensor(COLOR, SENSOR_LIGHT); Wait(SHORT_WAIT); b = COLOR*100; //read the blue color scale by 100 SetSensor(COLOR, SENSOR_TOUCH); //toggle power to change to channel 0 SetSensor(COLOR, SENSOR_LIGHT); if(r>g){max = r;}else{max = g;} //find the color with max intensity if(b>max){max=b;} if(r