3 Pots Color Diffuser

dheinzerling's picture

 

Description

  • Use the Arduino to control 3 LEDS using 3 potentiometers. The user can adjust each potentiometer to control the brightness of each individual LED. For each LED/potentiometer link, if the pot is turned up to the maximum setting, the light begins to blink at a fixed rate.

Components Used

  • Light Emitting Diodes (LED)
  • Resistors
  • Potentiometers

Arduino Code

 

/*
* Based on "Coffee-cup" Color Mixer code
* Control 3 LEDs with 3 potentiometers
* If the LEDs are different colors, and are directed at diffusing surface (stuck in a
*   a Ping-Pong ball, or placed in a paper coffee cup with a cut-out bottom and 
*   a white plastic lid), the colors will mix together.
* Each potentiometer will control the brightness of one of the LEDs. If the pot is turned all the way up
*   the LED that it is controlling will start to blink.
*
*/
 
// Analog pin settings
int aIn = 0;    // Potentiometers connected to analog pins 0, 1, and 2
int bIn = 1;    //   (Connect power to 5V and ground to analog ground)
int cIn = 2;  
 
// Digital pin settings
int aOut = 9;   // LEDs connected to digital pins 9, 10 and 11
int bOut = 10;  //   (Connect cathodes to digital ground)
int cOut = 11;  
 
// Values
int aVal = 0;   // Variables to store the input from the potentiometers
int bVal = 0;  
int cVal = 0;  
 
void setup()
{
  pinMode(aOut, OUTPUT);   // sets the digital pins as output
  pinMode(bOut, OUTPUT);   
  pinMode(cOut, OUTPUT); 
}
 
void loop()
{
 
  aVal = analogRead(aIn) / 4;  // read input pins, convert to 0-255 scale
  bVal = analogRead(bIn) / 4; 
  cVal = analogRead(cIn) / 4;  
 
  if (aVal > 240)
  {
    analogWrite(aOut, aVal);    // Send new values to LEDs
    delay(500);
    analogWrite(aOut, 0);
    delay(500);
  }
  else
  {
    analogWrite(aOut, aVal);   
  }
  if (bVal > 240)
  {    
    analogWrite(bOut, bVal);
    delay(500);    
    analogWrite(bOut, 0);    
    delay(500);
  }
  else
  {
    analogWrite(bOut, bVal);
  }
  if (cVal > 240)
  {        
    analogWrite(cOut, cVal);
    delay(500);
    analogWrite(cOut, 0);
    delay(500);
  }
  else
  {
    analogWrite(cOut, cVal);
  }
}
hw3photo.JPG
0
Your rating: None