I need to figure out how to fade in and out of multiple LEDS in a function with an Arduino. Can't use delay() because other things need to run while the light is fading. This is what it has so far, but does not work.
int value = 0; // variable to keep the actual value
int ledpin = 9; // light connected to digital pin 9
int p1 = 0;
void setup()
{
// nothing for setup
Serial.begin(9600);
}
void loop()
{
inout(50, 30, 9, 0, 0);
//inout(20, 20, 10);
}
void inout(int inDelay, int outDelay, int ledpin, long previousmil, int done)
{
if(millis() - previousmil>inDelay){
if (value <=255){
analogWrite(ledpin, value); // sets the value (range from 0 to 255)
value+=5;
}
previousmil=millis();
}
if(value = 260)
done = 1;
if(millis() - previousmil>outDelay && done == 1){
if (value >0){
analogWrite(ledpin, value); // sets the value (range from 0 to 255)
value-=5;
}
previousmil=millis();
}
}