I have two LEDs an I want the first one getting linear brighter and the second one do the exact same thing just one ore two seconds later. When one LED has reached 100, it should getting darker until there's no light and then start again from the beginning. I#m trying now for quite a long time but couldn't get it going.
int LED = 11;
int LED2 = 10;
void setup() {
Serial.begin(9600);
}
int x;
int x2;
void loop() {
for(x = 0; x<=100;x++)
{
while(x > 30)
{
for(x2 = 0; x2<=100;x2++)
{
analogWrite(LED2,x2);
delay(100);
}
}
analogWrite(LED,x);
delay(100);
Serial.println(x);
}
}
I just wanted to do the beginning but it isn't working. Can somebody pleas help me?
sin
andcos
to create a sinusoidal brightness profile. Loop from 0 to 2xPI at whatever increment you want (maybe use a DEG2RAD conversion so you can work in degrees) and cycle around a circle. Usesin
to calculate the brightness of one LED ((sin(angle) + 1) * 50.0
) andcos
for the other. The two LEDs will then be 90° apart around the circle.