Hi there,
I have made a simple LED program with 4 LED's (4 colours) in total. I was able to fade all LED and to apply a delay time to them. The 4 LED will start fading in or out all at the same time. My problem is that I would like to fade the 4 LED independently from each other with their own delay time and I can't see to get this done. I have included my code below, maybe you could give me some useful tips.
I was wondering if the Arduino is able to run more than one program (sketch) at the same time. This would also help resolve this problem since I could set up 4 different independently programs for each of these LED's. Can you please help?
Thank you very much.
Elio.
I am using the Mega 2560 board.
/*
Fading
Program created:
8-Feb-2013
*/
int ledPin = 12; // LED connected to digital pin 12
int redPin = 11; // LED connected to digital pin 11
int bluPin = 10;
int grePin = 9;
void setup() {
// formula here is: 127.5 * (x) = ( x = delay in seconds)
// fade in from min to max in increments of 2 points:
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=2) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
analogWrite(redPin, fadeValue);
analogWrite(bluPin, fadeValue);
analogWrite(grePin, fadeValue);
// First stage ramp up taking 4 hours
delay(112941);
}
// formula here is: 3 * (x) = final in seconds ( x = delay in sec)
for(int fadeValue = 255 ; fadeValue >= 250; fadeValue -=2) {
analogWrite(ledPin, fadeValue);
analogWrite(redPin, fadeValue);
analogWrite(bluPin, fadeValue);
analogWrite(grePin, fadeValue);
delay(2400000);
}
for(int fadeValue = 250 ; fadeValue <= 255; fadeValue +=2) {
analogWrite(ledPin, fadeValue);
analogWrite(redPin, fadeValue);
analogWrite(bluPin, fadeValue);
analogWrite(grePin, fadeValue);
delay(2400000);
}
// fade out from max to min in increments of 2 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=2) {
// sets the value (range from 255 to 0):
analogWrite(ledPin, fadeValue);
analogWrite(redPin, fadeValue);
analogWrite(bluPin, fadeValue);
analogWrite(grePin, fadeValue);
// Last stage ramp down taking 4 hours
delay(112941);
}
}
void loop() {
}