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
1
vote
1answer
317 views

Calculating with millis()

The following code works fine until I turn the if (tijd - action >= 500) into if (tijd - action >= 1000) I wonder why this fails. If I just loop and print the tijd - action it has no problem ...
0
votes
2answers
730 views

Press on pressure sensor once, turn on LED for 6 seconds

I am working on a project where I would like to press on a pressure sensor (0-1024) once and turn on the LED and turn off by itself after 6 seconds. I am quite new to arduino and I can't seem to ...
1
vote
3answers
4k views

Arduino Blink two LEDs without Delay(amount of repetitions)

Arduino community. I have had experience with Arduino for 3 years now and have finally come to the conclusion to get rid of the delay function entirely. Below is the code to blink two LEDs a ...
1
vote
2answers
10k views

Converting `millis()` to decimal seconds?

I would like to get my Arduino to print milliseconds as decimals of seconds. For example, instead of printing 10456, printing 10.456 I have tried to set a float value or millis, and dividing by 1000 ...
1
vote
2answers
58 views

Make something happen on a continous input just once and for a specific amount of time

My project is very complicated, but here is a visual synthesis The input actually comes from a kinect, that detects a person position through Processing, which I connected via Serial to Arduino. ...
1
vote
1answer
1k views

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 ...
0
votes
1answer
849 views

Using millis() function to start at potentiometer reading

I am trying to use the millis() function to start a countdown of 3 seconds when I turn my potentiometer to high travel. My code so far starts the timer at the beginning of the loop or when reset is ...
1
vote
2answers
420 views

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) =...
0
votes
3answers
159 views

Millis…alternate flash

I thought I had the Millis() command sorted but i'm stumped on the one. Aim is to get 2 led's alternately dimming, they work great with delay(); of course....but i can't figure where i'm going wrong ...
1
vote
1answer
111 views

millis() vs creating a “long” variable

I think my issue is not fully understanding how the millis() function works; I am wondering the difference between simply creating a variable such as long fake_millis ++ ; vs using millis()?
0
votes
2answers
510 views

What am I doing wrong with my millis()?

Im new to Arduino and have been trying to use the millis() function for an assignment of mine. I have had a lot of trouble trying to get the millis() function to work but now it seems to be working ...
0
votes
1answer
1k views

Change from using the external crystal to the internal oscillator

BACKGROUND I have made my own Arduino PCB based on the circuit of the Arduino Pro Mini (below) (including the external oscillator). I have already written the firmware and the code is stable. The ...
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. ...
0
votes
3answers
740 views

Time.h rollover after 49.7 days [duplicate]

I'm developing a arduino based system, which includes a alarm system. Searching on the Internet, I found these lybraries "Time.h" and "TimeAlarms.h". In the requirements, it says: "Time does not ...
2
votes
0answers
104 views

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 ...
2
votes
1answer
418 views

How to use millis()

I'm trying to have a keypad do two one of three things when a key is pressed: If the 1 is pressed I want LED 1 to blink twice then stay on If either the 2 or the 3 is pressed I want LED 2 to blink ...
3
votes
1answer
6k views

How can I replace pulseIn with interrupts?

I have an HC-SR04 sensor and I need to get the distance from it. I use this code: digitalWrite(trig, LOW); delayMicroseconds(2); digitalWrite(trig, HIGH); delayMicroseconds(10); digitalWrite(trig, ...
0
votes
1answer
708 views

Faster and lighter approximate timing code without using timer

I want to use loop() iterations counter to execute some tasks periodically or tasks like debouncing. My other sketch is running every loop() at least 20 ms, and if i am using 5 ms time to wait to ...
1
vote
2answers
3k views

How often can I ping an HC-SR04 ultrasonic sensor?

In my current project, I want the sensor to be continuously scanning for a value of less than 30cm. I was wondering how long of a delay I need (if any) between each call of the ping function. It ...
0
votes
2answers
166 views

Sketch does not work without delay() or other complex functions like digitalWrite()

I have a simple sketch here that should just blink a led once a second or so (approximately): boolean onOff=true; int count=0; void setup() { pinMode(13, OUTPUT); } void loop() { count++; ...
1
vote
1answer
149 views

How come my code does not wait for a specific time before going into an if statement?

I have an HC-SR04 attached to a servo. When the 90 degree reading is less than 30 cm, I want the motor to take 2 seconds to turn to 130 degrees, get a measurement on the right, and turn back to 90 ...
0
votes
3answers
1k views

millis() function always returns same value

I'm trying to program an Arduino MKR1000 and I am using the millis() function to emulate a traditional timer. The problem is that any call to millis() inside the debounceTimer() function returns the ...
0
votes
1answer
41 views

Why does my servo execute an action in the beginning when the odds are almost 0?

I made a servo motor turn if the result of random(0, 10000) is less than or equal to 1. If that is the case, the motor turns to 130 degrees, to 50 degrees, and then to default position(90 degrees). It ...
0
votes
1answer
1k views

Help me restructure code for multitasking Neopixel + IR remote + arduino

First of all, I'm completely new to both arduino, and programing. Second, as for a good newbie, i'm trying to build a fairly complicated project. So, any help and suggestion is welcome. The goal is: ...
0
votes
1answer
742 views

How to delay outside loop

I am using a function outside loop(), which is called after an interrupt. Inside this function, I am setting several relays that need to change after a second or two, depending on my setting. I tried ...
0
votes
1answer
917 views

ATtiny44 millis() not working with 16 MHz external clock

I'm using ATtiny44 with Arduino IDE according to this tutorial: http://highlowtech.org/?p=1695 I have a problem with millis(). When I use an internal 1 MHz clock it works correctly but when I use ...
1
vote
2answers
3k views

How can I made my Arduino follow the time exactly?

I am making an Arduino clock. You can set time to it, and then it keeps on going. The problem is that it is always within a minute off. It is not a major issue, but one that I would like to fix. I use ...
1
vote
3answers
741 views

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 ...
1
vote
3answers
1k views

How to rewrite code in millis?

I am currently working on a project that makes a plateua move back and forth using a stepper motor. On this plateau I have attached LEDs that create patterns. However, the plateau should be moving ...
1
vote
1answer
1k views

millis() in a millisecond stopwatch

I'm making a stopwatch that will measure time between two points. I want that stopwatch to have a millisecond accuracy. After the start when someone touch the pad it will show like the time of the ...
0
votes
1answer
107 views

Arduino Blocks at Uploading

I am trying to make an operating hours counter with arduino, i started with a basic script to make the arduino work as a stop watch, This is my script: unsigned long start=0, finish=0, elapsed=0; ...
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)....
1
vote
2answers
2k views

Why doesn't my 7 segment update every second like in the program?

I used sevseg.h library to write numbers to my 4 digit seven segment. The display should update every second with the current time since program started running. This is my code so far: #include <...
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 ...
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 ...
-2
votes
1answer
396 views

Arduino millis() won't work

This is my program. The LED should turn off after four seconds. int vraag = 7; int gloeikaars = 5; unsigned long previousMillis3; boolean gloeistate = true; void setup() { pinMode(gloeikaars, ...
2
votes
1answer
1k views

Should millis() be stored in a variable once each loop, or called for every reference?

When comparing the value of millis() numerous times per loop(), are there reasons for/against storing it in a variable once at the top of loop(), v.s. calling millis() each time? The most basic ...
1
vote
1answer
1k views

millis() not working properly

I'm doing a little project that, on a press of a button, will light up three LEDs and then will turn off the LEDs in different times. I'm using the millis() function to control the time that each LED ...
1
vote
3answers
910 views

Managing timer intervals using millis at random intervals

I am doing a project which needs to meet the following specifications. On receiving an SMS arduino will start switching 1st relay on after some time duration(say 30 Seconds) relay 1 will be ...
0
votes
2answers
81 views

Issue with simple project

I'm new to Arduino and today I have a problem with this code: int led_1 = 10; int led_2 = 11; int led_3 = 12; int button = 3; int time = 0; byte val = 0; void setup() { // put your setup code here,...
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 ...
2
votes
2answers
1k views

Measurement of pulse duration greater than 3mins

Is it possible to measure the width of a pulse which is longer than 3 minutes? The pulseIn function can only measure duration of maximum 3 minutes accurately. I've tried using interrupts but haven't ...
1
vote
2answers
4k views

run two motors in turns without using delay()

I googled solutions and tried, but I still cannot get it working. I've tried BlinkwithoutDelay. I feel it is very confusing to track timing of two motors (i.e., step, direction, speed) for the ...
0
votes
2answers
358 views

How do I set the motor state to “HIGH” at the beginning of this sketch?

My intent with this sketch is to have motors run for one minute, then stand by for 18 minutes. In practice, the sketch starts the motor state at "low" for the OffTime interval, then goes to the OnTime ...
1
vote
2answers
718 views

Is it correct to use pulseIn() in ISRs?

Since it is not right to use millis() in an ISR to calculate duration of the input, Is it correct to use pulseIn()?
7
votes
4answers
2k views

Adjust time calculation after Timer0 frequency change

I have an Arduino Nano with an 328P and need all 6 PWM pins. Thus, I had to adjust the prescaler and WGM Mode of Timer0. It is now in phase correct PWM mode with a prescaler of 1. TCCR0A = _BV(...
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 ...
3
votes
4answers
13k views

Measuring Time Between Inputs

I'm trying to measure the amount of time that has passed between every time a reed switch mounted on a wheel is activated to calculate the speed of a bike in miles per hour and display it on two 7 ...
1
vote
4answers
1k views

need help for saving the millis function when arduino was rebooted

I have two questions want to ask I'm using Arduino Uno with 16*2 LCD Blue ( also I have temp. sensor and two motors also 3 limit switches) ,, my code is working good, but sometimes my lcd stop ...
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 ...