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