// AMBIENT LIGHT // declare program constants const int greenPin = A0; // the analog pin for the potentiometer controlloing the green LED const int bluePin = A1; // the analog pin for the potentiometer controlling the blue LED const int redPin = A2; // the analog pin for the potentiometer controlling the red LED const int greenLEDpin = 9; // the digital pin for the green LED const int blueLEDpin = 10; // the digital pin for the blue LED const int redLEDpin = 11; // the digital pin for the red LED // declare program variables int greenVal = 0; // between 0 and 255 int blueVal = 0; // between 0 and 255 int redVal = 0; // between 0 and 255 int greenSenseVal = 0; // between 0 and 1023 int blueSenseVal = 0; // between 0 and 1023 int redSenseVal = 0; // between 0 and 1023 // set up the program void setup(){ Serial.begin(9600); pinMode(greenLEDpin, OUTPUT); pinMode(blueLEDpin, OUTPUT); pinMode(redLEDpin, OUTPUT); } // run the loop of the led void loop(){ greenSenseVal = analogRead(greenPin); // A0 input will affect the green LED delay(5); // delay by 5 milliseconds blueSenseVal = analogRead(bluePin); // A1 input will affect the blue LED delay(5); // delay by 5 milliseconds redSenseVal = analogRead(redPin); // A2 input will affect the red LED // convert the analog inputs into digital output values between 0 and 255 greenVal = greenSenseVal/4; // will convert to a number between 0 and 255 blueVal = blueSenseVal/4; // will convert to a number between 0 and 255 redVal = redSenseVal/4; // will convert to a number between 0 and 255 // display the serial values on screen Serial.print("Green Value: "); Serial.print(greenVal); // should be between 0 and 255 Serial.print(", Blue Value: "); Serial.print(blueVal); // should be between 0 and 255 Serial.print("Red Value: "); Serial.println(redVal); // should be between 0 and 255 // write these values to their digitial output analogWrite(greenLEDpin, greenVal); analogWrite(blueLEDpin, blueVal); analogWrite(redLEDpin, redVal); }