Go Down

Topic: Timer (Read 257 times) previous topic - next topic

Lavan


I am doing my first project and looking for the timer code to turn the output ON / OFF after certain time say 1 minute or 5 minutes.  Currently I am using millis() to achieve this, but I think there will be a better way to do this, any suggestions are welcome!!!

Currently I am using below sketch to turn OFF the output after 1 minute.
********************************

unsigned long time;
void setup() {
  pinMode(13, OUTPUT);
  pinMode(9, INPUT);
}

void loop() {
  if (digitalRead(9) == HIGH)
{
  digitalWrite(13, HIGH);
    time = millis();
   
    }

if (millis() - time > 60000)
{
digitalWrite(13, LOW);

}
}

PaulS

On the top of every single page is a link to the Playground. On the main playground page, there is a link, in the left column, to user contributed libraries. A number of them relate to timing.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy