Questions tagged [millis]

Is a standard library function. It returns the number of milliseconds since the Arduino board began running the current program.

Filter by
Sorted by
Tagged with
101
votes
4answers
75k views

How can I handle the millis() rollover?

I need to read a sensor every five minutes, but since my sketch also has other tasks to do, I cannot just delay() between the readings. There is the Blink without delay tutorial suggesting I code ...
1
vote
2answers
3k views

How to simulate delay() to debounce mechanical button using millis()?

Im trying to use the millis() function as a replacement for the delay() function in order to debounce a mechanical button. This is for an electric drum kit I am building. Im using a teensy Arduino to ...
17
votes
5answers
9k views

How do I get an accurate time?

I've made a clock using an Arduino, but the time seems to drift. I am aware of the rollover issue; the clock seems to drift by about 15 minutes over the course of a week. I'm using a custom PCB with ...
3
votes
3answers
28k views

Resetting millis() and micros()

I want to know how much time has elapsed since a certain event, and I do not want to use any external timers. It seems logical to reset an internal timer whenever the event occurs (using an interrupt)....
13
votes
3answers
42k views

Using millis() and micros() inside an interrupt routine

The documentation for attachInterrupt() says: ... millis() relies on interrupts to count, so it will never increment inside an ISR. Since delay() requires interrupts to work, it will not work if ...
0
votes
1answer
157 views

millis() replace delay() question

// each "event" (LED) gets their own tracking variable unsigned long previousMillisLED12=0; unsigned long previousMillisLED13=0; unsigned long previousMillisLED3=0; // different intervals for each ...
5
votes
4answers
3k views

How to keep accurate millis() while using ADC_sleep mode?

millis() uses timer0 (linked to CPU clock) to count time, but ADC_sleep mode stops the CPU clock, therefore millis() will drift (lag behind) after each ADC conversion performed in ADC_sleep mode. ...
4
votes
4answers
19k views

millis() function with a button press

I am trying to use the millis() function to turn on a pin for a specified interval then turn off and turn on a second pin. It is intended to power a relay and offer a visual cue to when the cycle is ...
2
votes
3answers
318 views

How can I find the time taken while a function is being called? [duplicate]

I tried using millis, but I wanted to know if there is any better way to find out the exact time from when a function is called and finally when it terminates.
2
votes
1answer
5k views

nodeMCU - Millis() - Simple Counter - How long is LED on?

PROGRESS, now I have this (WITH GREAT HELP): void setup() { Serial.begin(9600); // initialize digital pin 13 as an output. } uint32_t timer_start = 0; int timer_running = false; void loop() { // ...
2
votes
3answers
100 views

How to use millis() in my code instead of delay()?

I'm having issues trying to convert my code to non-blocking. I was able to do so in some parts, but the rest aren't the same. When I try to replace delay with an if statement like the spinning and ...
1
vote
1answer
1k views

How to start particular event for particular time using millis()?

In my recent project, I want to run particular event for the particular time. For example, If I want to Turn ON my LED for 20 Second. And rest time LED must be off. I know using delay() it is possible ...
1
vote
2answers
511 views

State Machine Logic problem with added states monitoring safety switches

I have been working on getting a state machine to work correctly but am having trouble with adding in the last bit of logic. What it needs to do is several things: Read two button inputs. Make sure ...
1
vote
0answers
102 views

Change delay function to millis function to play music

I'd like to write a code by changing the delay function in the music playing code to the millis function, do you know how? #include "pitches.h" // notes in the melody: int melody[] = { ...
1
vote
3answers
179 views

Problem with Dual Safety Switches Initiating Timed Relay

I have been working on an Arduino project that has me kind of stumped. What it needs to achieve is that two momentary safety switches need to be pushed and held within a specified time frame as ...
1
vote
1answer
975 views

Is it possible to replace this delay with millis()? (And issue with other millis loop)

I am working on updating a project and I have a thread over in the Arduino forum which helped me out, but I'm a bit stuck, and there isn't much activity going on there. This code is for use with a ...
0
votes
2answers
149 views

Restart sequence of NeoPixel stick with a push button at any time

I am really happy with my new Arduino stuff and playing around with all those pixels :). I am new to programming and it's difficult to understand it, but with every success, I grow in knowledge. My ...