Lab 3: Potentiometer-based color dimmer

Posted by sgeiger

sgeiger's picture

Description

Use 3 potentiometers to control the intensities of red, blue, and green light emitting diodes.  Output current intensity to serial.

Components Used

  • 3 Light Emitting Diode (LED)
  • 3 Resistors
  • 3 Potentiometers
  • 1 Dimmer

Video

http://www.youtube.com/watch?v=UKexeLkaadA

Arduino Code

 

/* 
 * Potentiometer-based color dimmer
 * ---------------
 * Three potentiometers control the brightness of R,G,B LEDs 
 *
 * No command structure, outputs intensity values to serial
 *
 * Created 13 Feb 2011
 * CC-BY 2011 R.Stuart Geiger, stuart@stuartgeiger.com
 * 
 */
 
 
int redPin   = 10;   // Red LED,   connected to digital pin 9
int greenPin = 9;  // Green LED, connected to digital pin 10
int bluePin  = 11;  // Blue LED,  connected to digital pin 11
 
int rDec=0;
int bDec=0;      //intensity of R,G,B values in decimal, 0-255
int gDec=0;
 
void setup() {
  pinMode(redPin,   OUTPUT);   // sets the pins as output
  pinMode(greenPin, OUTPUT);   
  pinMode(bluePin,  OUTPUT);
  Serial.begin(9600);          
  analogWrite(redPin,   255);   // set them all to full brightness
  analogWrite(greenPin, 255);   // set them all to full brightness
  analogWrite(bluePin,  255);   // set them all to full brightness
}
 
void loop () {  
 
      //reset RGB intensity values
      rDec=0;
      gDec=0;     
      bDec=0;
 
      //pull the pot values
      rDec=analogRead(A2);
      gDec=analogRead(A1);
      bDec=analogRead(A0);
      
      //analogRead gives value 0-1023, scale it to 0-255
      rDec=rDec/4;
      gDec=gDec/4;     
      bDec=bDec/4;     
    
      //verbosity
      Serial.print("R:");
      Serial.print(rDec);
      Serial.print(" G:");
      Serial.print(gDec);
      Serial.print(" B:");
      Serial.println(bDec);
      
      //write the colors
      analogWrite(redPin, rDec);
      analogWrite(greenPin, gDec);
      analogWrite(bluePin, bDec);
      
        
  delay(100);  // wait a bit, you've got time 
 
}
Potentiometer Lab 3
0
Your rating: None
Tags: