[Description]
1. One pot changes both direction and speed of color flow
2. The other pot changes the balance of duration between colors
[Components]
- Potentiometer X 2
- Resistor X 3
- LED X 3 (R, G, B)
[Arduino Code]
int pot1Pin = 0;
int pot2Pin = 2;
int pot1Val = 0;
int pot2Val = 0;
int led1Pin = 9; // select the pin for the LED 1
int led2Pin = 10; // select the pin for the LED 2
int led3Pin = 11; // select the pin for the LED 3
int duration = 0; // duration of a LED on
int bal1 = 1; // color balance for led1;
int bal2 = 1; // color balance for led2;
int bal3 = 1; // color balance for led3;
void setup() {
pinMode(led1Pin, OUTPUT);
pinMode(led2Pin, OUTPUT);
pinMode(led3Pin, OUTPUT);
}
void loop() {
pot1Val = analogRead(pot1Pin); // read the value from pot 1, between 0 - 1024, for duration balance bewteen colors
pot2Val = analogRead(pot2Pin); // read the value from pot 2, between 0 - 1024, for direction & speed of color flow
// 1. changing duration balance between colors
if (pot1Val <= 512) {
bal1 = 1;
bal3 = (512-pot1Val+128) / 128;
bal2 = (bal1+bal3) / 2;
}
else {
bal3 = 1;
bal1 = (pot1Val-512+128) / 128;
bal2 = (bal1+bal3) / 2;
}
// 2. changing direction & speed of color flow
if (pot2Val <= 512) {
led1Pin = 11;
led3Pin = 9;
duration = pot2Val;
}
else {
led1Pin = 9;
led3Pin = 11;
duration = (1024 - pot2Val);
}
analogWrite(led3Pin, 0);
analogWrite(led1Pin, 255);
delay(duration * bal1);
analogWrite(led1Pin, 0);
analogWrite(led2Pin, 255);
delay(duration * bal2);
analogWrite(led2Pin, 0);
analogWrite(led3Pin, 255);
delay(duration * bal3);
}
[Picture]
Assign 3[Description]
Comments
looks good!
looks good!