Description
My submission has three potentiometers, which control three LEDs. One controls color (the LEDs cycle smoothly from red to blue to green), one controls brightness, and one controls blink rate.
At very low blink rates, the LEDs simply looked faded, so I modified the code so that the lowest blink rate still looks like it's blinking, and the highest rate will simply leave the LED on.
Components Used
List what you used in your assignment.
Example:
1- Arduino Pro Mini 3.3V
1- Breadboard
3- 220 Ω Resistor
1- Red LED
1- Green LED
1- Blue LED
1- Cotton pad
String
3 - Potentiometer
Code
/*
*
* Control 3 LEDs with 3 potentiometers
* a controls blink rate, b controls brightness, and c controls color.
*
*/
// 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;
// Variables for comparing values between loops
int i = 0; // Loop counter
int wait = (1000); // Length of blink
// Color values
int r = 0;
int g = 0;
int b = 0;
int checkSum = 0; // Aggregate pot values
int prevCheckSum = 0;
int sens = 3; // Sensitivity theshold, to prevent small changes in
// pot values from triggering false reporting
// FLAGS
int PRINT = 1; // Set to 1 to output values
int DEBUG = 1; // Set to 1 to turn on debugging output
void setup()
{
pinMode(aOut, OUTPUT); // sets the digital pins as output
pinMode(bOut, OUTPUT);
pinMode(cOut, OUTPUT);
Serial.begin(9600); // Open serial communication for reporting
}
void loop()
{
i += 1; // Count loop
aVal = (analogRead(aIn)/10)*10 + 30; // read input pins, convert to appropriate values
bVal = analogRead(bIn) / 4;
cVal = (analogRead(cIn)*3)/4;
Serial.println(aVal);
Serial.println(bVal);
Serial.println(cVal);
wait = aVal;
if(cVal < 256) {
r = 255 - cVal;
g = cVal;
b = 0;
} else if(cVal < 512) {
cVal = cVal%256;
g = 255 - cVal;
b = cVal;
r = 0;
} else {
cVal = cVal%256;
b = 255 - cVal;
r = cVal;
g = 0;
}
r = (r*bVal)/255;
g = (g*bVal)/255;
b = (b*bVal)/255;
analogWrite(aOut, r); // Send new values to LEDs
analogWrite(bOut, g);
analogWrite(cOut, b);
delay(wait);
if(aVal < 1050) {
analogWrite(aOut, 0);
analogWrite(bOut, 0);
analogWrite(cOut, 0);
}
delay(wait);
Serial.println();
}
void setColor(int color) {
}
Images
http://i43.tinypic.com/2076gqe.jpg
- Login to post comments