Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
1 vote
1 answer
108 views

Fixing a pedestrian traffic light sequence pattern in a cycle using millis and without delay

I was emulating the pedestrian traffic light cyclic pattern (red, green, green flashing) in the next Arduino code. But when I run this code with my ESP8266 Wemos D1 mini controller, it appears the ...
Hong Christian Lin Jiang's user avatar
2 votes
1 answer
5k views

How to set the sampling frequency in Arduino without using a delay

I am reading an ECG signal using a single lead heart rate monitor. What I know is that when I use delay(15) it means that I am getting 66.67 readings in a second which corresponds to the sampling ...
Ahmed K. Moustafa's user avatar
3 votes
1 answer
9k 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, ...
shurup's user avatar
  • 300
0 votes
2 answers
234 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++; ...
user2882440's user avatar
0 votes
1 answer
1k 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 ...
nicolaasb's user avatar
14 votes
4 answers
54k 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 ...
Petr's user avatar
  • 253
5 votes
4 answers
7k views

Is `millis()` affected by long ISRs?

I have a project that uses timers and interrupts frequently. A lot of CPU time is spent handling ISRs over an extended period of time. Would this affect code inside the main loop that relies on the ...
Anonymous Penguin's user avatar