I've successfully completed the "Color Mixing Lamp" tutorial on page 53 of the Arduino Projects Book. Now I'm just tweaking the code to see if I can make some improvements.
I would like to show how much each of the photoresistors contributes to the overall sensor voltage, so that I can express the value in an "Illumination Fraction:" field.
To do this, I've added a few new float variables to the code:
int totalSensorValue = 0;
float redFraction = 0.00;
float greenFraction = 0.00;
float blueFraction = 0.00;
I've also added this to the void loop() section:
totalSensorValue = redSensorValue + greenSensorValue + blueSensorValue;
redFraction = redSensorValue/totalSensorValue;
greenFraction = greenSensorValue/totalSensorValue;
blueFraction = blueSensorValue/totalSensorValue;
Serial.print("\t Total Sensor Value: ");
Serial.print(totalSensorValue);
Serial.print("\t Illumination Fraction: \t Red: ");
Serial.print(redFraction);
Serial.print("\t Green: ");
Serial.print(greenFraction);
Serial.print("\t Blue: ");
Serial.println(blueFraction);
Here's the problem. The values I get back are all zero:
Total Sensor Value: 1062 Illumination Fraction: Red: 0.00 Green: 0.00 Blue: 0.00
What's going on here? I'm using an Arduino Ono R3 with the Aduino IDE 1.0.6. I will post the entire sketch if you need more info.