Pages: [1]   Go Down
Author Topic: Timer  (Read 206 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 83
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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

}
}
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 551
Posts: 46227
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: