HansDia:
It does not work properly, it should first dim led1 and LED2 up and down where LED1 and LED2 runs opposite of each other in 10 seconds as func1 () says it should. So after that they should dimmed liked each other up and down for 10 seconds as FUNC2 () says. Then start over.
Sorry for my bar english
You used delay, so you are separating the two functions for 10 seconds rather than running them for 10s.
You can try this to see if it does what you want, alternating between the two functions for 10s...
int led1 = 3;
int led2 = 5;
unsigned long ledTimeStart;
void setup()
{
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
Serial.begin(9600);
ledTimeStart = millis();
}
void loop()
{
if (millis() - ledTimeStart <= 10000UL)
{
func1();
}
else if (millis() - ledTimeStart <= 20000UL)
{
func2();
}
else
{
ledTimeStart = millis();
}
}
void func1()
{
for (int x = 0; x < 255; x = x + 5)
{
int omv = map(x,0,255,255,0);
analogWrite(led1,x);
analogWrite(led2,omv);
delay(19);
}
for (int x = 255; x > 0; x = x - 5)
{
int omv = map(x,0,255,255,0);
analogWrite(led1,x);
analogWrite(led2,omv);
delay(19);
}
}
void func2()
{
for (int x = 0; x < 255; x = x + 5)
{
analogWrite(led1,x);
analogWrite(led2,x);
delay(19);
}
for (int x = 255; x > 0; x = x - 5)
{
analogWrite(led1,x);
analogWrite(led2,x);
delay(19);
}
}
also,
FYI this expression will decrement an LED through its entire range of briteness in increments of 5:
for (int x = 255; x >= 0; x = x - 5)
yours, will not because it will not turn the led completely off (i.e. x=0):
for (int x = 255; x > 0; x = x - 5)
look at your loops to see if you want to bring the LED to full briteness or zero briteness and modify the expressions to reflect what you would like to have.
Not critical, but worth noting.