I tried that and didn't work for me
const int whiteLed = 2;
const int blueLed = 3;
long prevWhiteTimeMillis = 0;
boolean whiteState = false;
long prevBlueTimeMillis = 0;
boolean blueState = false;
unsigned long currentMillis;
void setup() {
// put your setup code here, to run once:
pinMode(whiteLed, OUTPUT);
pinMode(blueLed, OUTPUT);
}
int timer = 0;
void loop() {
currentMillis = millis();
blueLedControl();
whiteLedControl();
}
int whiteLedBrightness = 0;
int whiteLedMaxBrightness = 50;
boolean whiteLedSwitch = false;
void whiteLedControl() {
if (currentMillis - prevWhiteTimeMillis >= 500 / 25) {
if (whiteLedBrightness >= whiteLedMaxBrightness) {
whiteLedSwitch = true;
}
if (whiteLedBrightness <= 1) {
whiteLedSwitch = false;
}
if (!whiteLedSwitch) {
if (whiteLedBrightness <= whiteLedMaxBrightness) {
whiteLedBrightness++;
} else {
whiteLedSwitch = true;
}
} else {
if (whiteLedBrightness >= 0) {
whiteLedBrightness--;
} else {
whiteLedSwitch = false;
}
}
prevWhiteTimeMillis = currentMillis;
}
analogWrite(whiteLed, whiteLedBrightness);
}
int blueLedBrightness = 0;
int blueLedMaxBrightness = 50;
boolean blueLedSwitch = false;
void blueLedControl() {
if (currentMillis - prevBlueTimeMillis >= 500 / 50) {
if (blueLedBrightness >= blueLedMaxBrightness) {
blueLedSwitch = true;
}
if (blueLedBrightness <= 1) {
blueLedSwitch = false;
}
if (!blueLedSwitch) {
if (blueLedBrightness <= blueLedMaxBrightness) {
blueLedBrightness++;
} else {
blueLedSwitch = true;
}
} else {
if (blueLedBrightness >= 0) {
blueLedBrightness--;
} else {
blueLedSwitch = false;
}
}
prevBlueTimeMillis = currentMillis;
}
analogWrite(blueLed, blueLedBrightness);
}