Questions tagged [millis]

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

Millis is a standard library function. It returns the number of milliseconds since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 50 days.

For more, see the standard reference.

176 questions
14
votes
1 answer

How millis() resets itself to 0

Looking at the documentation for the millis() function , it says: Returns the number of milliseconds since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 50 days. How's…
Programmer
  • 362
  • 4
  • 11
5
votes
4 answers

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 over. Several of these need to eventually be…
HiWay
  • 109
  • 1
  • 1
  • 11
2
votes
3 answers

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 sensors debounce it doesn't work at the right time,…
2
votes
1 answer

Does millis() work inside a function?

So I know that millis() doesn't work how it's suppose to if you use it in an interrupt but lets say we have a code that looks like below, will millis() work properly or how it behaves in an interrupt? Do I need to use the delay() instead of millis()…
Brit
  • 41
  • 1
  • 6
2
votes
3 answers

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

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
0 answers

Start LED blink at certain millis() value

I was looking at the blink without delay sketch and I was trying to modify it so the LED would start blinking after 1000 ms. I changed the previousMillis variable to 1000, but the program didn't change. In fact, it doesn't seem to change for any…
1
vote
1 answer

Assign a delay value generated by a random function called randomBlink()

I'm trying to make a sketch where my led blinks with random delay. I have 2 functions: ledBlink() and randomBlink(). The randomBlink use as delay parameter a random number "r" generated from 1 to 499 and pass this value to the ledBlink function to…
tommy
  • 29
  • 6
1
vote
1 answer

Blink LED with different on off times just once with millis

So Im having trouble trying to figure this out. My project needs a valve to stay shut and when an event is triggered, 3 seconds into that event the valve opens for 2 seconds, then remain shut till it's triggered again. I was just treating it like an…
Jason8899
  • 23
  • 4
1
vote
1 answer

Millis timer question

Trying to figure out how to do this in millis. So right now the code works just fine, plays mp3_play(2) while a push button is closed then plays mp3_play(1) when its open. Lets say I want mp3_play(2) to play while the push button closed but after 4…
Jason8899
  • 23
  • 4
1
vote
2 answers

Running Arduino with 2 outputs and 2 inputs

Totally new to Arduino, 3 weeks old! I am doing a project with 2 inputs (2 x ultrasonic sensors) and 2 outputs (buzzer and send SMS) The code to run the buzzer and sms works perfectly individually. For the buzzer, it will stop buzzing after approx 5…
Zac
  • 11
  • 2
1
vote
2 answers

Reaction timer using millis

I've written this code for a reaction timer game. The reaction time is to be displayed in milliseconds to the serial monitor as accurately as possible. The reaction time is not being displayed correctly. I'm including my timer setup routine and…
MochaJ
  • 11
  • 2
1
vote
1 answer

Cycling LED's for specific time period with millis()

My goal in pseudo code is : only LED-6 HIGH for 6 seconds, then only LED-7 HIGH for 2 seconds, then only LED-8 HIGH for 4 seconds, then restart This is very easy with delay(), but I struggle with millis(). Here is my code. Only led 7 and 8…
Gerryandbob
  • 15
  • 1
  • 6
1
vote
2 answers

Delaying an action inside a function

My current function is supposed to play a sound effect, then after the sound effect is done (14 seconds), perform the next action (digitalWrite(CONTROLLINO_R1, LOW)). if (digitalRead(CONTROLLINO_A8) == HIGH && !skeleLatch) { skeleLatch = 1; …
Ricky Mason
  • 113
  • 3
1
vote
3 answers

trying to use millis()

I'm learning how to use the millis() function. Instead of having it in the main body of the program I wanted to place it in a function so I can change the time interval with which an led will flash. I modified the code blinkWithoutDelay. My code is…
1
vote
1 answer

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 one wire temperature sensor, however, each time it…
XOIIO
  • 11
  • 3
1
2