In this assignment, I used 2 potentiometers to control the RGB LED lights. The first potentiometer would determine which colors to turn on while the second potentiometer would determine the brightness of the selected color(s). For example, for low range of the Pot2 (below 340), only the red LED would be ON at Pot1 value of brightness; for mid range of Pot2 (between 340 and 680), red and green would be ON, red and green LEDs would be ON at Pot1 value of brightness and for high range of Pot2 (above 680), all the 3 LEDs would be ON at Pot1 value of brightness.
- Components Used:
- 1 Arduino Uno Controller
- 1 Bread Board
- 3 220 Ohm Resistors
- 2 Potentiometers
- 3 RGB LEDs
- Wires for connections
Note about the circuit images: Since I forgot to incorporate the potentiometers in the frame while taking the picture, I used my friend's bread board to reconnect my circuit and took another image with the potentiometers in the frame. Hence, the difference in the bread boards in the two images.
Code:
/* Old Code:
* one pot dims, the other pot changes the blinking rate
* modification of the following
* http://www.arduino.cc/en/Tutorial/AnalogInput
* Modified Code for Assignment in TUI:
* One pot controls the colors and the other controls the brightness.
* If pot2 is set to low, then only red is displayed; for pot2 at medium, red and green are displayed and for pot2 at high, all three are displayed at full brighntess
*/
int pot1Pin = 1; // select the input pin for the potentiometer 1
int pot2Pin = 2; // select the input pin for the potentiometer 2
int pot1Val = 0; // variable to store the value coming from pot 1
int pot2Val = 0; // variable to store the value coming from pot 2
int redPin = 9;
int greenPin = 11;
int bluePin = 10;
void setup() {
pinMode(redPin, OUTPUT); // declare the redPin as an OUTPUT
pinMode(greenPin, OUTPUT); // declare the greenPin as an OUTPUT
pinMode(bluePin, OUTPUT); // declare the bluePin as an OUTPUT
Serial.begin(9600);
analogWrite(redPin, 0); // set them all to low brightness
analogWrite(greenPin, 0); // set them all tolow brightness
analogWrite(bluePin, 0); // set them all to low brightness
}
void loop() {
pot1Val = analogRead(pot1Pin); // read the value from pot 1, between 0 - 1024, for dimming
pot2Val = analogRead(pot2Pin); // read the value from pot 2, between 0 - 1024, for blinking
/*delay(pot2Val); // stop the program for some time, meaning, LED is on for this time
analogWrite(redPin, 0); // dim LED to completely dark (zero)
analogWrite(greenPin, 0); // dim LED to completely dark (zero)
analogWrite(bluePin, 0); // dim LED to completely dark (zero)
delay(pot2Val); // stop the program for some time, meaning, LED is OFF for this time*/
if(pot2Val<=340){
analogWrite(redPin, pot1Val); // set red to pot1 value brightness
analogWrite(greenPin, 0); // set green to low brightness
analogWrite(bluePin, 0); // set blue to low brightness
}else if(pot2Val>340 && pot2Val<680){
analogWrite(greenPin,pot1Val); // set green to pot1 value brightness
analogWrite(redPin, pot1Val); // set red to pot1 value brightness
analogWrite(bluePin, 0); // set blue to low brightness
}else if(pot2Val>=681 && pot2Val<1024){
analogWrite(redPin, pot1Val); // set red to pot1 value brightness
analogWrite(greenPin, pot1Val); // set green to pot1 value brightness
analogWrite(bluePin, pot1Val); // set blue to pot1 value brightness
}
}
- Login to post comments