Skip to main content
10 votes
Accepted

What does a delay(0) actually do?

Delay (traditionally) has two functions that it performs: Wait for a period Yield processing to other threads through the yield() weak symbol. By using a delay(0) the author thinks they are saying &...
Majenko's user avatar
  • 105k
5 votes

Water pump relay switching too fast

The problem lies in the specification itself. According to your rules, what should the pump do if the water level is exactly 2 cm? Granted, there is no such thing as an exact physical measurement. But ...
Edgar Bonet's user avatar
  • 43.3k
4 votes

Random "Compilation error: Error: 13 INTERNAL: exit status 1". No clue how to resolve or even what causes this error

The problem with that error message is that you are only reading the very last line. That line says "Oops, it didn't compile". The actual error message occurs before that. You need to read ...
Majenko's user avatar
  • 105k
4 votes
Accepted

How to Independently run positional and continuous servos using millis()?

This is covered in the Blink Without Delay Arduino tutorial. Let me paraphrase the main part of the example code here: uint8_t ledState = LOW; uint32_t lastTimeLedChanged = 0; void loop() { ...
Edgar Bonet's user avatar
  • 43.3k
3 votes

Is there a need to put a delay in the main loop

There is no absolute need for any Arduino program to use delay() The blink without delay sketch that is included in the standard sketch examples is the canonical illustration of this. In most cases ...
RedGrittyBrick's user avatar
3 votes
Accepted

Tone() function pauses between notes

there is // to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(...
Juraj's user avatar
  • 18k
3 votes
Accepted

Using 1 ms delay() in a for loop to check inputs.. Bad?

You can do this, for quite simple sketches. It starts to become ugly if you add more features and conditions. Therefore, the "correctTM" (read: professional) way is to implement a state ...
the busybee's user avatar
  • 2,088
3 votes
Accepted

Functions delaying gesture sensor recognition

The code is being slowed down by the delay() function because it is a blocking function. The delay function does not exit until delay time passes, so no other functions can run, such as sensor reading....
jsotola's user avatar
  • 1,515
2 votes

Using Millis instead of delay to reboot relay

A general approach to remove a delay() is to replace it by some code that: takes note that some action (whatever follows the delay()) will have to be performed in the future takes note of the ...
Edgar Bonet's user avatar
  • 43.3k
1 vote

Using 1 ms delay() in a for loop to check inputs.. Bad?

What's bad about this? It looks a bit clunky but I suppose there is nothing particularly bad about it (apart from your typo of digitalWrite rather than digitalRead). I would do it more like: unsigned ...
Nick Gammon's user avatar
  • 38.4k
1 vote

Question about using millis for alarm conditions - Arduino

You are missing a delay here: for (byte i = 0; i < repeat; i++) { digitalWrite(buzzer, !digitalRead(buzzer)); } Without the delay, the whole loop terminates so fast that you cannot hear ...
Edgar Bonet's user avatar
  • 43.3k
1 vote

Is there a need to put a delay in the main loop

No, there is no need to use delay() at all. Unlike the sleep() or deepSleep() commands, delay does not save power or do anything else that's special. The standard implementation of delay is just doing ...
PMF's user avatar
  • 1,296

Only top scored, non community-wiki answers of a minimum length are eligible