Hello guys, does anyone know how can i reset the time in Arduino? For example, i want my program running a period of time, e.g one minute, stopping and starting all over again automatically?That's what i used so far:
long interval = 60000;
void setup() {
}
void loop(){
t = millis;
while(millis()- t <= interval)
{
//do something;
}
}
The problem i face is that the program,which it's in brackets, is running, only, one minute and then stops forever. >:( >:(
void setup() {}
void loop() {
//do something;
}
This program runs 1 minute, stopps and restarts immediately.
Just an empty sketch? hahaha
Of course but i was referred about the code in brackets , which it's inside the while loop.That code runs for a minute and doesn't restart.
The same code is running in my loop and restarts automatically.
Dunno , the values from an analog temperature sensor that are printed in my serial monitor , they , completely, stop after one minute.
I can give you an example with a little different specification.
Button on pin 2 (closing to GND) starts the process,
here flash the builtin LED for 10 seconds with 100 ms on and 100 ms off.
After the 10 seconds this can be restarted.
#include <Bounce2.h>
const unsigned long duration = 10000;
const unsigned int blinkFor = 100;
const byte buttonPin = 2;
Bounce Start;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Start.attach(buttonPin, INPUT_PULLUP);
}
void loop() {
static unsigned long startTime;
static unsigned long blinkTime;
static bool idle = true;
unsigned long topLoop = millis();
if (idle) {
if (Start.update()) {
if (Start.fell()) {
startTime = topLoop;
idle = false;
digitalWrite(LED_BUILTIN, HIGH);
}
}
} else if (topLoop - startTime >= duration) {
idle = true;
digitalWrite(LED_BUILTIN, LOW);
} else {
if (topLoop - blinkTime >= blinkFor) {
blinkTime = topLoop;
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
}
}