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

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 พ.ย. 2024

ความคิดเห็น • 57

  • @programmingelectronics
    @programmingelectronics  4 ปีที่แล้ว +2

    ****If you like this, I think you'll like the premium Arduino training we offer. You can check it out here**** bit.ly/3lHyzcB

    • @charmindesai3730
      @charmindesai3730 3 ปีที่แล้ว

      Please make a video on how to use arduino timers

    • @michaelzajac5284
      @michaelzajac5284 3 ปีที่แล้ว

      I was seriously considering about delay(2000) mean 2 seconds?

    • @yashaswikulshreshtha1588
      @yashaswikulshreshtha1588 3 ปีที่แล้ว +1

      Lol I like how the lens was listening music and how you were pouring those components like something to be used for recipe LOL

  • @etiennegrix1738
    @etiennegrix1738 5 ปีที่แล้ว +3

    😉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!!!!

  • @ivanivan4418
    @ivanivan4418 4 ปีที่แล้ว +1

    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

  • @josephanthony9294
    @josephanthony9294 4 ปีที่แล้ว +1

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

  • @VasilisKarastergios
    @VasilisKarastergios 5 ปีที่แล้ว +1

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

  • @jon_raymond
    @jon_raymond 5 ปีที่แล้ว +6

    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.

  • @philipanderson9434
    @philipanderson9434 ปีที่แล้ว +1

    Awesome explanations, I really enjoying this approach to teaching.

  • @spianny
    @spianny 2 ปีที่แล้ว +1

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

  • @billgaytes6845
    @billgaytes6845 8 หลายเดือนก่อน +1

    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 ?

    • @programmingelectronics
      @programmingelectronics  8 หลายเดือนก่อน

      Great question!
      By default all the digital pins are set as inputs, so it's not necessary here. However, on my better days I usually explicitly set them as inputs using the pinMode function, as i feel like it is more clear, so i should have done that here as well.

  • @0124akash
    @0124akash หลายเดือนก่อน

    Hello sir, can I use emonlib with millis function ? It's worked?

  • @mkamranchaudhry680
    @mkamranchaudhry680 3 ปีที่แล้ว +1

    Really very help full info and solid info

  • @chucklearnslithics3751
    @chucklearnslithics3751 2 ปีที่แล้ว +1

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

    • @programmingelectronics
      @programmingelectronics  2 ปีที่แล้ว +1

      Great question! I have not explored branchless programming much, so I don't really have a take on it quite yet.

    • @chucklearnslithics3751
      @chucklearnslithics3751 2 ปีที่แล้ว

      @@programmingelectronics Yeah, I usually try to write my Arduino code as branchless as I can, but I have no idea if it makes a difference or not. I suspect it does. Some compilers are smart enough to take your conditional logic and optimize it into branchless logic, but I have doubted the native Arduino compiler has been built to do that. But I just don't know at the end of the day.

  • @vilmariojunior1
    @vilmariojunior1 4 ปีที่แล้ว +1

    thank you for explaining

  • @elektro860
    @elektro860 4 ปีที่แล้ว +1

    this is what i need

  • @joshuapitong899
    @joshuapitong899 2 ปีที่แล้ว +1

    Thank you ❤

  • @VidarrKerr
    @VidarrKerr 7 หลายเดือนก่อน

    What is "Pay with checks"?

  • @mohamedessamhadid231
    @mohamedessamhadid231 5 ปีที่แล้ว +1

    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 😂

  • @quintonmcguinness6512
    @quintonmcguinness6512 4 ปีที่แล้ว +1

    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.

  • @ipadize
    @ipadize 2 ปีที่แล้ว +1

    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

  • @mrphysh
    @mrphysh ปีที่แล้ว +1

    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.

  • @christopherlyons7613
    @christopherlyons7613 ปีที่แล้ว

    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.

  • @PleaseWait...
    @PleaseWait... 3 ปีที่แล้ว

    Can i put delay on a for loop?

  • @donaldklopper
    @donaldklopper 3 ปีที่แล้ว +1

    Yeah. Speling is easy ;-)

  • @ThuanDuong-pv3xu
    @ThuanDuong-pv3xu 4 ปีที่แล้ว

    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 ?)

    • @DaleDix
      @DaleDix 4 ปีที่แล้ว

      Want a pat on the head?

    • @TurbidSugar19
      @TurbidSugar19 3 ปีที่แล้ว

      No. You created serial communication with 9600 changes per second, which in ideal world could be 9600 bit persecond speed. Even if i consider that 100% of data sended where actual words IceIcebaby, still, we got 10 letters(char) ,which are 10*8 =80 bits .
      80/9600 this is what you idealy can send to screen, if you write drivers by yourself , without silence/parity check/stop bit and etc . Not all bits you send are part of data, some used for communication purposes.
      Moreover not really sure that every clock event instruction execute for every arduinos, are all of them "arm" based?

  • @Conorkc86
    @Conorkc86 5 ปีที่แล้ว +7

    Easy to spel. made me laugh :-)

  • @nanditofernandeshornay8967
    @nanditofernandeshornay8967 2 ปีที่แล้ว

    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..???.

  • @venkatchowdary
    @venkatchowdary 4 ปีที่แล้ว

    bro i need one clarity will you help me

  • @prvashisht
    @prvashisht 2 ปีที่แล้ว +1

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

  • @ThuanDuong-pv3xu
    @ThuanDuong-pv3xu 4 ปีที่แล้ว

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

  • @gurilab
    @gurilab 2 ปีที่แล้ว +1

    cheio de humor...kkkk...dah dah duh dah...

  • @robbs96
    @robbs96 5 ปีที่แล้ว

    LMAO! SNL reference. NICE DUDE!

  • @DevoTecho
    @DevoTecho 3 ปีที่แล้ว

    This was delay function.. not miles

  • @camilobregon
    @camilobregon 4 ปีที่แล้ว

    THICK L00P

  • @o-h-1
    @o-h-1 5 ปีที่แล้ว +1

    Bathroom Break😂

  • @kresimirkekovladic8932
    @kresimirkekovladic8932 3 ปีที่แล้ว

    and I ask you. are you normal ? You explain the difference between delay and millis and insert the for function. And how extensively you explain sorry but this video is Scary !!!!!

  • @danhyatt2206
    @danhyatt2206 ปีที่แล้ว

    you spelled 'spell' wrong lol

  • @brucesmith9144
    @brucesmith9144 4 ปีที่แล้ว

    Easy to spel???
    Oops! Missed an “l” there.

    • @mikenco
      @mikenco 4 ปีที่แล้ว +1

      You didn't get the joke, huh?...