Hi All,
Sorry if this is an annoying question, but after going over the Blink without delay and a few other examples of that function I'm still confused. What I have is a single LED increasing then decreasing in brightness (greenLED) then I have 6 LED's turning on and off one after another (redLED). What I would like to happen is for the greenLED to be lighting up and down whilst the redLED's go in sequence. But so far my code seems to run and ignore the timers I've put into it. Should be pretty obvious, but I'm completely new to C++ so any help would be greatly appreciated. Here is my code:
int led = 11;
int brightness = 0;
int delayTime = 5;
int ledCount = 7;
int ledPins[] = { 3, 4, 5, 6, 7, 8, 9 };
int ledDelay = 75;
const unsigned long greenLEDinterval = 500;
const unsigned long redLEDinterval = 1000;
unsigned long greenLEDtimer;
unsigned long redLEDtimer;
void setup() {
pinMode(led, OUTPUT);
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
greenLEDtimer = millis ();
redLEDtimer = millis ();
}
}
void toggleGreenLED ()
{
while(brightness < 170)
{
analogWrite(led, brightness);
delay(delayTime);
brightness = brightness +1;
}
while(brightness > 5)
{
analogWrite(led, brightness);
delay(delayTime);
brightness = brightness - 1;
}
greenLEDtimer = millis ();
}
void toggleRedLED ()
{
for (int thisLed = 0; thisLed < ledCount-1; thisLed++) {
digitalWrite(ledPins[thisLed], HIGH);
delay(ledDelay);
digitalWrite(ledPins[thisLed], LOW);
}
for (int thisLed = ledCount-1; thisLed > 0; thisLed--) {
digitalWrite(ledPins[thisLed], HIGH);
delay(ledDelay);
digitalWrite(ledPins[thisLed], LOW);
}
redLEDtimer = millis ();
}
void loop ()
{
if ( (millis () - greenLEDtimer) >= greenLEDinterval)
toggleGreenLED ();
if ( (millis () - redLEDtimer) >= redLEDinterval)
toggleRedLED ();
}
Thanks for any help