Arduino delay() and millis() Functions: Tight Loops and Blocking Code

preview_player
Показать описание
🤩 FREE Arduino Crash Course 👇👇

***Read the transcript of this video on our website***

***About Us:***
This Arduino tutorial was created by Programming Electronics Academy. We are an education company who seek to help people learn about electronics and programming through the ubiquitous Arduino development board.

***We have no affiliation whatsoever with Arduino LLC, other than we think they are cool.***
Рекомендации по теме
Комментарии
Автор

😉thank you for explaining the whole millis delay confusion from start to finish this will definitely help a lot of guys programming what they've always wanted.
Can't wait for the next lesson!!!!

etiennegrix
Автор

This is very clear explanation for people like us. Please also make a video about interrupt. Those videos on utube are not as clear explanation

ivanivan
Автор

Really great explanation! I might mention that delay() could also be explained as its own loop that has nothing in it other than counting the time given to it. This fits well with your explanation of the actual loop.

jon_raymond
Автор

Looking forward for the millis(); series. Thanks for sharing your knowledge with us.

VasilisKarastergios
Автор

Excellent tutorial. Great explanations that clear up any misunderstandings ...and nice sense of humour. Thank you

josephanthony
Автор

Awesome explanations, I really enjoying this approach to teaching.

philipanderson
Автор

this is the greatest arduino content ive ever come accross!! Thank you soooo much and keep it up! please :)

spianny
Автор

Please help. I am building a small alarm system. When sensor is triggered the siren must trigger and after 3 minutes switch of till the next trigger.

quintonmcguinness
Автор

good. My application is ... like a weather station: the Arduino is full of sensors, and I want to take data and put it into Python and then into a database. And I want a data sample every fifteen miinutes.

mrphysh
Автор

In your example you have specified the buton pin = 5. However in void setup, you don't use [pin mode (button pin, input)], is that not necessary ?

billgaytes
Автор

Thank you very much, I hv always suffered a lot from this issue bt I couldn't find the correct way to phrase it in order to troubleshoot it 😂

mohamedessamhadid
Автор

Really very help full info and solid info

mkamranchaudhry
Автор

Not sure I agree with your definition of tight code. In general the specific length of time a loop spends is not really the main issue whether a loop is tight or not. A tight loop just has a non-blocking structure, so the time it takes to process is consistent with each run through the loop. When you introduce calls into a loop that will not provide consistent times to process than the tightness of your loop (and code) is compromised (think database calls, I/O reads, network processing calls, etc). I would say the example you give with the delay() function IS a tight loop (although generally not a goid programming practice due to the blocking). It will always stop your code for the set time so the loop time is consistent.

christopherlyons
Автор

I'm curious about your take on branchless programming for tight Arduino loops.

chucklearnslithics
Автор

I am currently programming my arduino to move my camera to specific places and take pictures, a focus stacker. I am currently at over 1000 lines of code, is this a tight loop? :P

ipadize
Автор

I watched just for the music recipe and didn't get it :p

prvashisht
Автор

Sr. please make the code bellow becomes millis:


Void loop () {
if (digitaRead (tombol)==0){
digitalWrite (led, HIGH);
delay (3000);
digitalWrite (led, LOW);
delay (3000);
digitalWrite (led, HIGH);
delay (3000);
digitalWrite (led, HIGH);
delay (3000);
}
else {
digitalWrite (led, LOW);
}
}

How to be version millis Sr..???.

nanditofernandeshornay
Автор

to:
Programming Electronics Academy
I ask mysefl that the ATmega328, 16 MHz crytal ; It will enforcement 16 million structrures per second so...16M/12 structrures to print the sentence "Ice Ice Baby" are 1, 333, 333 time per second ( mean Can It print 1, 333, 333 sentences "Ice Ice Baby" per second ?)

ThuanDuong-pvxu
Автор

...So in smartphone We need multi cores, multi threads (hardware) multi functions (software) to play multimedia !!

ThuanDuong-pvxu
Автор

bro i need one clarity will you help me

venkatchowdary