Questions tagged [millis]
Is a standard library function. It returns the number of milliseconds since the Arduino board began running the current program.
175
questions
1
vote
2
answers
127
views
Working with pulseIn() and millis()
I'm trying to use pulseIn with elapsed time using millis(), I don't want to use interrupts instead of pulseIn (I need pulseIn because I need accurate pulse time), the elapsed time doesn't need to be ...
1
vote
2
answers
456
views
Stepper motor micros (millis) non-blocking delay simple example?
I am trying to get a simple non-blocking replacement for:
digitalWrite(stepPinX, HIGH);
delayMicroseconds(500);
digitalWrite(stepPinX, LOW);
delayMicroseconds(500);
This is what I tried, and the ...
0
votes
2
answers
1k
views
The same button with one click and double click [closed]
i hope to get some help with my code.
I am trying to distinguish between a single press and a quick double press of the button with debouncing.
I am making some silly mistake in my code and i can't ...
0
votes
1
answer
120
views
Using Millis instead of delay to reboot relay
I want to reboot relay (turn off , waiting 4 seconds and turn ON)
it works perfectly if I use delay(4000), but code is blocked while delay (4 seconds) and I cant start relay 2.
How can I use Millis ...
-2
votes
1
answer
185
views
LED blink patterns with multiple LEDs with millis() not using Delay()
I want to make LED blink patterns with multiple LEDs with the millis() function. I researched about it but did not find a perfect solution.
I found one blog, but it is using a LED pin number array; I ...
0
votes
1
answer
431
views
Milliseconds using square wave RTC
i am trying to make a code that prints the time hh:mm:ss:ms using RTC,i have made it using millis() but it is not accurate +/-2 milliseconds
ho can i make it using sq wave and intterupt
here is the ...
0
votes
3
answers
406
views
Using 1 ms delay() in a for loop to check inputs.. Bad?
So first off, I know millis() exists. Just asking out of curiosity. Say you have a button you wanna check for during a delay.. Maybe a 10 second delay. So you make a for loop that checks for input and ...
2
votes
2
answers
550
views
Toggle button switches through case statements with button debouncing
The overview of my code is that I want a toggle button to be pushed and each button push will move the code to the next case statement. In each case statement, there will be different LED functions. I ...
2
votes
2
answers
77
views
Trying to keep my main code running unless an input is LOW for a certain amount of time
I have code that creates a sequential signal with 4 LEDS. It cascades to the right. This works when I hold down the input button. What I need help with is having the code run exactly the same when ...
0
votes
1
answer
255
views
Question about using millis for alarm conditions - Arduino
I am new to programming in general and to Arduino as well.
I am working on a small project to improve my ability to write complete and kind of useful programming sketches.
I am facing a problem. I am ...
3
votes
1
answer
574
views
How do I run 4 LEDs sequentially based off of a push button input?
I am trying to create a program that runs 4 LEDs sequentially while also being able to do other things with different inputs and outputs. Because of this, I am using the millis function and not the ...
0
votes
1
answer
252
views
Question about ElapsedMillis() library and state machines
I'm making a sort of state machine with 3 states, and I'm actually doing some tests by configuring at the start of my code state=3. I've wired on each pin 2 leds, for a total of 12 leds. I'm using ...
1
vote
1
answer
500
views
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 ...
2
votes
1
answer
456
views
How to Independently run positional and continuous servos using millis()?
I am setting up 3 servos (2 position servos and 1 '360' continuous rotational servo) with Arduino. but I failed to run these independently. It runs one after another. I wish to run it in loop ...
2
votes
1
answer
277
views
Is there something that I need to do to make the code from this answer compile?
I tried to compile the following code (using Arduino 1.8.16 with an esp8266-12)
extern volatile unsigned long timer0_millis;
unsigned long new_value = 0;
void setup(){
//Setup stuff
}
void loop(){
...
5
votes
1
answer
719
views
Delay() and millis() functions don't work in cpp external files
I'm currently facing an issue using delay() and millis() functions in an external cpp file.
The issue is that when I used delay() in my main program (meaning .ino file) it works well but when I call ...
1
vote
1
answer
820
views
How to reset ESP32 after a certain duration?
I would like to reset my ESP32 from the software, how do I do it and how to make it do this at regular intervals.
1
vote
2
answers
2k
views
Arduino Reset via Software (every day)
Dear Stack Exchanger's,
I want to reset my Arduino and system in every 24h for preventing frozen software and also other connectivity stuffs.
I wrote a program which connects a digital pin to reset ...
1
vote
2
answers
316
views
run a function for a certain amount of time! [duplicate]
i'm working on a project where i need to run a function for 20 minutes and the function writes to memory using EEPROM every minute. How can i make the function run for 20 minutes, i was thinking of ...
2
votes
2
answers
1k
views
How to write nonblocking code, for polling sensor at 100 Hz
I'm using this piece of code to try to poll an IMU sensor at 100 Hz (for a AHRS sensor fusion library).
void loop(void)
{
// nonblocking code variables
static uint32_t last_ms;
uint32_t ms;
// ...
1
vote
0
answers
47
views
What happens if Millis() method variable goes out of it's capacity? [duplicate]
I am now working on a project which is expected to last at least 5 years from the time it is completed. In that project, i can not use delay() for some purposes so I am using millis() method
unsigned ...
3
votes
1
answer
91
views
Fader OOP Problem
This code works and it can fade three LEDs without any problem, obviously you can even add more of them : )
// Pins Definition
const int button1 = 13;
const int button2 = 12;
const int button3 = 11;
...
1
vote
1
answer
459
views
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'...
0
votes
2
answers
1k
views
Display upTime using `millis()` - Arduino Uno
I want to use the following function to display MCU's uptime, but after several hours I get error.
void uptime(char *ret_clk)
{
byte days = 0;
byte hours = 0;
byte minutes = 0;
byte seconds = ...
1
vote
2
answers
677
views
How to call multiple delayed functions using a single millis()
I am working in a project where I need to call more than 1 functions actually 4 functions using a single millis()
Here is the code below.
unsigned long then = 0;
void loop(){
unsigned ...
0
votes
1
answer
67
views
Using millis() in unsynchronized manner
I am assuming millis() is a Timer ISR function.
If so :
When using millis() as mentioned in Arduino Reference :
unsigned long currentMillis = millis();
What would happen if the ISR asynchronously ...
1
vote
1
answer
709
views
How to use millis instead of delay? [duplicate]
Sorry if something similar has been answered before...
I am working on a garden timer project that runs on a ESP8266 based NodeMCU and is integrated with Blynk.
I have a waterNow function that ...
1
vote
1
answer
92
views
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) ...
1
vote
1
answer
146
views
Get production count for current minute
I am trying to make a production counter for a machine. I want to display production count of the last minute for each seconds. So, display should update every second and should display real value of ...
0
votes
1
answer
2k
views
ESP32 millis not working properly
I have a program which measures temperatures every 30 minutes and sends them to a database. Immediately after running the program the first measurement is sent, however, the second (which should be ...
1
vote
2
answers
465
views
Using millis() instead of delay() when playing a melody
I want to make my Arduino to play several simple melodies, and also be able to skip a melody by pressing a button and go on with the next song. therefore I cannot use delay() because the code should ...
1
vote
1
answer
40
views
How can I remove the delays in this code for sweeping the servo?
I know this is probably a very asked question, but I am building a fairly basic radar type thing which sweeps left and right and uses an ultrasonic sensor to determine the distance to an object and a ...
1
vote
1
answer
206
views
Issue with simple timer based on millis()
Sorry to bother but I am at my wits end. I'm experimenting with timers, and starting very simple. The following code is supposed to print the content of a variable each time an interval of time has ...
1
vote
2
answers
286
views
Switch on the piezo emitter for a short time
I need a short beep for every minute of change. I wrote a separate function. The signal duration should be 50 ms, the rest of the time the emitter connected to the A1 contact should be silent.
A ...
1
vote
0
answers
26
views
error ph meter cant show the data [duplicate]
im using ph meter DFROBOT v1.0 at i compiled the code from the DFROBOT web this is the code
*
# This sample code is used to test the pH meter V1.0.
# Editor : YouYou
# Ver : 1.0
# Product: ...
1
vote
1
answer
188
views
Timing push button code
I am trying to time how long button is held for. The code seems to work but with two problems:
the millis values are being read wrongly. If you hold the button for 1 second, it returns holdTime of ...
2
votes
2
answers
957
views
smooth DC motor control with millis
So the task is to control 12v DC motor.
With first button, you can add up motor speed by certain speed step.
With second button, you can slow down motors speed by certain speed step.
With third button ...
0
votes
1
answer
163
views
Arduino stuck in PT_WAIT_UNTIL
I am using the Protothread Library from Adam Dunkels.
It is supposed to wait 1 second and then continue. But instead it gets stuck there and everything after that line is not executed.
lastTimeBlink = ...
2
votes
1
answer
95
views
Relays just switch ON and OFF on delay(), not on millis()
I use fuzzy logic for the running time of relays, but the relays just switch ON and OFF at the interval of the delay() I put at the end of loop.
This is my code:
void loop () {
ph = -180/100.0;
...
1
vote
3
answers
176
views
Ignoring the first high output from the sensor
If the vibration sensor with Arduino detects two high inputs within 1 minute, I want the led to flash in one second.
My ability to write Arduino code is very low; I tried with millis() but I couldn't.
...
2
votes
1
answer
230
views
Help with millis to get accurate timing
I'm essentially trying to create a music box which is light activated using an LDR. When it's open a song plays, while a servo rotates a figurine back and forth, and an LED dims and illuminates in ...
1
vote
0
answers
154
views
how to control 2 sensor and 3 relay with fuzzy
i'm using fuzzy to decide how long the relay on pump on and i got some trouble for it he just looping on relay how should i do thats my code
//---------Fuzzy 2.1 prelauch----------
//-----iNPUT ...
1
vote
2
answers
268
views
controlling 2 sensor and 3 pump using millis
i make a 3 pump for output and im using millis for it, i want to stop if rach the intervalm now in my code its still looping not realy stop for it thx
int pump1 = 5;//pin D5
int pump2 = 6;//pin D6
int ...
2
votes
3
answers
408
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 ...
3
votes
2
answers
280
views
How to use Multipile millis()
I've a exhaust fan that runs when the humidity is high. When the exhaust fan is on it should work for 3 minutes and should wait another 5 minutes to on. I am a beginner to this struggling for almost 2 ...
1
vote
0
answers
122
views
Change delay function to millis function to play music [duplicate]
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[] = {
...
0
votes
1
answer
134
views
how to ignore a sensor being tripped the first time and start recording millis on the 2nd time it is tripped
I am building a timing system that has a start, split and finish beams with this I am using a start gate that will drop when the race starts. when it drops it will trip the 1st sensor starting to ...
1
vote
0
answers
305
views
Run a dc motor for amount of time without delay
Hi everyone I have a project and I need to run a dc motor for amount of time without using delay I use DelayWithoutBlink technique.
In this code the motor should run for 5 second in cw then it will ...
1
vote
2
answers
752
views
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. ...
0
votes
1
answer
213
views
3 input (on/off/off with delay) to control 1device using ESP8266 as Web Server
I want to control one device in three ways : turn on / turn off / turn off with delay.
To do that i use an ESP8266 web server + android phone app.
The problem is that turn off with delay wont work.
It ...