Go Down

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


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);



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.
The art of getting good answers lies in asking good questions.

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!

via Egeo 16
Torino, 10131