How do you plan to solve it?
I solved this task in two main steps:
1.- I created a program that can increase the brightness of LED number 1 and 3 and decrease the LED numer 2 and 4 using the following code lines:
analogWrite(leds[0],i); // bright Increases
analogWrite(leds[2],i);
analogWrite(leds[1],255-i); // bright decreases
analogWrite(leds[3],255-i);
2.- I added a delay sentence where its time parameter depends on the adc value from a potenciometer to control the fade speed
/*Paste your code here*/
const char leds[] = {3,5,6,9};
const char pot = A0;
void setup() {
for(int i = 0; i<4; i++) pinMode(leds[i], OUTPUT);
for(int i = 0; i<4; i++) digitalWrite(leds[i], LOW);
}
void loop() {
for(int i=0; i<=255; i++){
int adc = map(analogRead(pot), 0, 1023, 300 , 1500);
analogWrite(leds[0],i);
analogWrite(leds[2],i);
analogWrite(leds[1],255-i);
analogWrite(leds[3],255-i);
delayMicroseconds(adc);
}
for(int i=255; i>=0; i--){
int adc = map(analogRead(pot), 0, 1023, 300 , 1500);
analogWrite(leds[0],i);
analogWrite(leds[2],i);
analogWrite(leds[1],255-i);
analogWrite(leds[3],255-i);
delayMicroseconds(adc);
}
}Add video of output (know more)
Add a photo of your hardware showing the output.
