Unsure why individual timers are not working. I am a new beginner

So I have 4 leds, 1 pulses regularly like a heartbeat. The other three are needed to go turnoff with 5 seconds in between each other. I have only just started, however I have read a lot of coding throughout the arduino website to try and help me. The program will easily time up to 5 seconds where the first led will turn off. However after that the other two do not go off at 10 seconds and then a gain at 15 seconds and I can't work out how. I have never used timers before only delays. However for the pulse to keep pulsing I can not use delay. Please note I am using an arduino lilypad if that makes any difference

For the timer I have used both int interval = 5000; to create the 5 seconds pause

but then 9000 does not work for 9 seconds etc. I did some research and saw how you use (60 * 60 * 1000); to make it work, however I still don't know why, I have done loads of research, but I just can't get my head around it. I don't even know it I'm doing it the right way. Any advice would be amazing to have Thank you

here is the code

int led7 = 7;// light that will go off int led8 = 8;// light that will go off int led9 = 13; // light that will go off const int LED = 9; // pulse led

unsigned long currentMillis; unsigned long previousMillis = 0; // will store last time LED was updated int interval = 5000; // interval at which to blink (milliseconds) int interval2 = ( 9 * 1000); int interval3 = (15 * 1000);

//sensor int sensorPin = 0; // light sensor is connected to analog pin 0 int sensorValue; // variable to store the value coming from the sensor

void setup() { digitalWrite(led7, HIGH); //makes leds default on digitalWrite(led8, HIGH); digitalWrite(led9, HIGH);

pinMode(led7, OUTPUT); pinMode(led8, OUTPUT); pinMode(led9, OUTPUT);

Serial.begin( 9600);

}

void loop () { //for sensor

/*Serial.println("And the value is: "); sensorValue = analogRead(sensorPin); // read the value of the sensor if (sensorValue >= 100) { // if the number is above 100, // digitalWrite(ledPin, HIGH); // turn the LED on Serial.println("too bright"); // send that value to the computer } else { // otherwise, //digitalWrite(ledPin, LOW); // turn the LED off Serial.println(sensorValue); // send that value to the computer } */

//for pulsing l.e.d static float in = 4.712; // controls how bright the .e.d goes by setting parameters from 0 -19 float out;

// do input, etc. here - as long as you don't pause, the LED will keep pulsing

in = in + 0.0005; // changes speed of fade by a lot if (in > 10.995) in = 4.712; out = sin(in) * 127.5 + 127.5; analogWrite(LED,out);

//unsigned long currentMillis = millis(); currentMillis = millis(); //led7turnoff if(currentMillis - previousMillis > interval) { previousMillis = currentMillis; digitalWrite(led7, LOW); }

//led8 turnoff if(currentMillis - previousMillis > interval2) { previousMillis = currentMillis; digitalWrite(led8, LOW); }

if(currentMillis - previousMillis > interval3) { previousMillis = currentMillis; digitalWrite(led9, LOW); } }

Hi

Because your first timer sets previousMillis to the current time, the other two timer if statements will never become true. The 5s timer will always become true first.

  if (currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;
    digitalWrite(led7, LOW);
  }

If you want each LED to go off and stay off, then I think you can just remove the previousMillis = currentMillis statements.

Also, change these variables to be unsigned long.

unsigned long interval = 5000UL;           // interval at which to blink (milliseconds)
unsigned long interval2 = 9000UL;
unsigned long interval3 = 5000UL;

Regards

Ray

oh wow, can't beleive I didn't see that.

Thanks Ray you have made my day. You have been a great help! :) XD