Description
* Each LED has its own pot which controls the speed at which it cycles through
* different brightness levels by determining the "jump" size between values.
* Because the LEDs calculate their output in mod 255 this has the
* benefit of allowing you to reverse direction and go from brighter to darker
* when the jump size is bigger than 255/2 (Like when car wheels can appear
* to be spinning backwards when they are at a certain speed).
*
* Setting a pot to mid range values (between 103-153 after being converted to a
* 255 scale) will hold it's brightness level constant. Turning the pot to
* either minimum or maximum value will likewise set the LED to 0 or 255.
Components
1- Arduino Uno
1 - Breadboard
3 - Potentiometers
3 - LEDs (red, green, blue)
3 − 220 Ω Resistors
1 - homemade diffusor
assorted wires
Code
/*
* by Jordan Arnesen, 1 Oct 2013
*
* Control 3 LEDs with 3 potentiometers
* Each LED has its own pot which controls the speed at which it cycles through
* different brightness levels by determining the "jump" size between values.
* Because the LEDs calculate their output in mod 255 this has the
* benefit of allowing you to reverse direction and go from brighter to darker
* when the jump size is bigger than 255/2 (Like when car wheels can appear
* to be spinning backwards when they are at a certain speed).
*
* Setting a pot to mid range values (between 103-153 after being converted to a
* 255 scale) will hold it's brightness level constant. Turning the pot to
* either minimum or maximum value will likewise set the LED to 0 or 255.
*
*/
// Analog pin settings
int rIn = 0; // Potentiometers connected to analog pins 0, 1, and 2
int gIn = 1; // (Connect power to 5V and ground to analog ground)
int bIn = 2;
// Digital pin settings
int rOut = 3; // LEDs connected to digital pins 9, 10 and 11
int gOut = 5; // (Connect cathodes to digital ground)
int bOut = 6;
// Values
int rPot = 0; // Variables to store the input from the potentiometers
int gPot = 0;
int bPot = 0;
int rVal = 0;
int gVal = 0;
int bVal = 0;
int rInc = 0; // Variable for brightness increment size
int gInc = 0;
int bInc = 0;
int wait = 500; // Delay between increments in brightness
void setup()
{
pinMode(rOut, OUTPUT); // sets the digital pins as output
pinMode(gOut, OUTPUT);
pinMode(bOut, OUTPUT);
}
void loop()
{
rPot = analogRead(rIn) / 4; // read input pins, convert to 0-255 scale
gPot = analogRead(gIn) / 4;
bPot = analogRead(bIn) / 4;
if ( rPot < 103|| rPot > 153) rVal += rPot; // increment currrent brightness by Pot value
if ( gPot < 103|| gPot > 153) gVal += gPot; // if Pot between 103-153 keep brightness same
if ( bPot < 103|| bPot > 153) bVal += bPot;
if ( rPot == 0 || rPot == 255) rVal = rPot; // if Pot is at min/max set LED to min/max
if ( gPot == 0 || gPot == 255) gVal = gPot;
if ( bPot == 0 || bPot == 255) bVal = bPot;
// Send new values to LEDs
analogWrite(rOut, rVal);
analogWrite(gOut, gVal);
analogWrite(bOut, bVal);
delay(wait);
}
- Login to post comments