I am trying to create a program in which a photoresistor controls a RGB led, changing the color of it depending on the light sensor value. Here is the code I have so far, but I don't know what to do about the bugs in it, any ideas?
--Here is the code :
const int RED_LED_PIN = 9; //Red LED Pin
const int GREEN_LED_PIN = 10; //Green LED Pin
const int BLUE_LED_PIN = 11; //Blue LED Pin
int lightPin = 0;
void setup() {
}
void loop() {
int lightLevel = analogRead(lightPin);
int redValue = constrain(map(lightLevel, 0, 512, 255, 0),0,255); //calculate the red Value (255-0 over the range 0-512)
int greenValue = constrain(map(lightLevel, 0, 512, 0, 255),0,255);
int blueValue = constrain(map(lightLevel, 512, 1023, 0, 255),0,255); //calculate the blue value 0-255 over 512-1023
lightLevel = map(lightLevel, 0, 900, 0, 255);
//adjust the value 0 to 900 to
//span 0 to 255
lightLevel = constrain(lightLevel, 0, 255);//make sure the
//value is betwween
//0 and 255
analogRead(lightLevel,lightPin)
{if (analogRead(lightLevel)) = map(lightLevel, 1, 99); // Display the requested color
analogWrite(RED_LED_PIN, redValue);
if(analogRead(lightLevel) map(lightLevel, 100,174 ));
analogWrite(GREEN_LED_PIN, greenValue);
if(analogRead(lightLevel) map(lightLevel, 175, 254));
analogWrite(BLUE_LED_PIN, blueValue);}
}