As you haven't shared your code, below will probably be more or less what your fade code looks like.
int fadeValue;
const int ledPin = 6;
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
for (int cnt = 0; cnt <= 255; cnt++)
{
analogWrite(ledPin, fadeValue);
fadeValue += 5;
delay(100);
}
for (int cnt = 255; cnt >= 0; cnt--)
{
analogWrite(ledPin, fadeValue);
fadeValue -= 5;
delay(100);
}
}
For demonstration, we will just use the first for-loop and leave the second for-loop out of the equation.
void loop()
{
for (int cnt = 0; cnt <= 255; cnt++)
{
// update the led
analogWrite(ledPin, fadeValue);
// update the brightness for the next time
fadeValue += 5;
// wait a bit
delay(100);
}
}
The trick is to split those for loops in smaller pieces that will do one step at a time. In the below code we let loop() do the looping instead of the for-loop; the effect should be the same as above.
void loop()
{
// update the led
analogWrite(ledPin, fadeValue);
// wait a bit
delay(100);
// update the brightness for the next time
fadeValue += 5;
// if over maximum, reset
if (fadeValue > 255)
{
fadeValue = 0;
}
}
If this is clear to you, we can add the decreasing of the brightnes back into this code. We use a variable fadeStep that will be positive to increase the brightnes and negative to decrease the brightness.
// the brightness level
int fadeValue;
// brightness steps
int fadeStep = 5;
// led pin
const int ledPin = 6;
And in loop() use that variable.
void loop()
{
// update the led
analogWrite(ledPin, fadeValue);
// wait a bit
delay(100);
// update the brightness for the next time
fadeValue += fadeStep;
// if maximum or minimum reached, change the 'direction'
if (fadeValue >= 255 || fadeValue <= 0)
{
fadeStep *= -1;
}
}
You can now put this in a function that you call repeatedly from loop().
void loop()
{
fade();
}
void fade()
{
// update the led
analogWrite(ledPin, fadeValue);
// wait a bit
delay(100);
// update the brightness for the next time
fadeValue += fadeStep;
// if maximum or minimum reached, change the 'direction'
if (fadeValue >= 255 || fadeValue <= 0)
{
fadeStep *= -1;
}
}
We now have a function that we can further optimise to get rid of the delay() in favour of *millis()).
bool fade()
{
// the brightness level of the led
static int fadeValue;
// time when the led's brightness needs to be updated
static uint32_t nextTime;
// the current time
uint32_t currentTime = millis();
// if it's time to update the led
if (currentTime >= nextTime)
{
Serial.println(fadeValue);
// set the next time
nextTime += fadeInterval;
// update the led
analogWrite(ledPin, fadeValue);
// update the brightness for the next time
fadeValue += fadeStep;
// if over maximum or minimum reached, change the 'direction'
if (fadeValue >= 255 || fadeValue <= 0)
{
fadeStep *= -1;
}
}
return true;
}
First we make use of some local variables that are static; this means that they are only known inside the function but will be remembered (don't go out of scope). The new fadeValue replaces the global fadeValue near the top of the original code. The variable nextTime indicates when the led's brightness needs to be updated; this variable is updated each time that you update the led's brightness. The variable currentTime keeps trackk of the current time (in millis()).
A new global variable fadeInterval is used to get rid of the hard-coded 100 milliseconds.
The function returns a bool that can be used in loop(); it's currently just a place holder in case you have additional requirements where you want to know if e.g. a fade from 0 to 255 to 0 has been completed.
If anything is not clear, ask.
You can now also write functions to flash random leds etc. and call them from loop(); use the same timing principles as demonstrated in the last fade(). E.g.
void random2()
{
}
void random3()
{
}
That's for you to fill in 
loop() will than look like
void loop()
{
fade();
random2();
random3();
}
The complete code:
// brightness steps
int fadeStep = 5;
// led pin
const int ledPin = 6;
// the fade interval
const uint32_t fadeInterval = 100;
void setup()
{
Serial.begin(57600);
while (!Serial);
pinMode(ledPin, OUTPUT);
}
void loop()
{
fade();
random2();
random3();
}
/*
fade led
Returns:
true
*/
bool fade()
{
// the brightness level of the led
static int fadeValue;
// time when the led's brightness needs to be updated
static uint32_t nextTime;
// the current time
uint32_t currentTime = millis();
// if it's time to update the led
if (currentTime >= nextTime)
{
Serial.println(fadeValue);
// set the next time
nextTime += fadeInterval;
// update the led
analogWrite(ledPin, fadeValue);
// update the brightness for the next time
fadeValue += fadeStep;
// if over maximum or minimum reached, change the 'direction'
if (fadeValue >= 255 || fadeValue <= 0)
{
fadeStep *= -1;
}
}
return true;
}
/*
randomly blink two leds
*/
void random2()
{
}
/*
randomly blink three leds
*/
void random3()
{
}