Тёмный

Arduino Sketch with millis() instead of delay() 

Programming Electronics Academy
Подписаться 226 тыс.
Просмотров 224 тыс.
50% 1

🤩 FREE Arduino Crash Course 👇👇
bit.ly/get_Arduino_skills
**If you like this, I think you'll like the premium Arduino training we offer. Check it out here** bit.ly/3nSBPUs
We designed this circuit board for beginners!
Kit-On-A-Shield: amzn.to/3lfWClU
SHOP OUR FAVORITE STUFF! (affiliate links)
---------------------------------------------------
Get your Free Trial of Altium PCB design Software
www.altium.com/yt/programming...
We use Rev Captions for our subtitles
bit.ly/39trLeB
Arduino UNO R3:
Amazon: amzn.to/37eP4ra
Newegg: bit.ly/3fahas8
Budget Arduino Kits:
Amazon:amzn.to/3C0VqsH
Newegg:bit.ly/3j4tISX
Multimeter Options:
Amazon: amzn.to/3rRo3E0
Newegg: bit.ly/3rJoekA
Helping Hands:
Amazon: amzn.to/3C8IYXZ
Newegg: bit.ly/3fb03X1
Soldering Stations:
Amazon: amzn.to/2VawmP4
Newegg: bit.ly/3BZ6oio
AFFILIATES & REFERRALS
---------------------------------------------------
►Audible Plus Free trial: amzn.to/3j5IGrV
►Join Honey- Save Money bit.ly/3xmj7rH
►Download Glasswire for Free:bit.ly/3iv1fql
FOLLOW US ELSEWHERE
---------------------------------------------------
Facebook: / programmingelectronics...
Twitter: / progelecacademy
Website: www.programmingelectronics.com/
**Arduino Sketch with millis() instead of delay() written tutorial**
www.programmingelectronics.co...

Опубликовано:

 

1 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 306   
@programmingelectronics
@programmingelectronics 3 года назад
****If you like this, I think you'll like the premium Arduino training we offer. You can check it out here**** bit.ly/3lHyzcB
@Darkstar327
@Darkstar327 2 года назад
please make a video on arduino sensor kit i need help on it btw your videos are amazing
@AlienRelics
@AlienRelics 4 года назад
Using previousTime = currentTime; will introduce an accumulating error. The time to process the code within the if statement will add to the time and accumulate. For just blinking LEDs or some other none critical stuff, no big deal. But if you simply use: previousTime += interval; You've just gotten rid of the cumulative error.
@programmingelectronics
@programmingelectronics 4 года назад
Thanks for bringing this up Steve!
@AlienRelics
@AlienRelics 4 года назад
@@programmingelectronics It probably won't affect most of what people will use this for, but it is just the sort of thing to drive you crazy later when you can't figure out why your timing is slipping.
@johncorbishley1548
@johncorbishley1548 4 года назад
I have always struggled with this, even with your videos from years ago. I have watched numerous videos and still struggled. This video is simply THE BEST! You have done so well as an experienced programmer to be able to explain to us newby's how this work is such an easy to understand way. I have been copying & pasting other peoples bits of code randomly getting results and as my projects get more complicated, that approach does not work. Well done, you are the best teacher on RU-vid for Arduino. No.1 Numero uno!
@cschmitz
@cschmitz 5 лет назад
This is a great explanation. The visuals really help wrap your head around the concept. Thanks for the vid!
@programmingelectronics
@programmingelectronics 5 лет назад
Thanks for watching!
@mariojulio993
@mariojulio993 4 года назад
It becomes very easy to learn from you. You make everything looks so simple. Thanks
@mykolasbauza
@mykolasbauza 3 года назад
Thank you for a wholesome explanation! Great stuff!
@shaswot
@shaswot 4 года назад
love the simplicity you bring into the explanation..... i had been reading up on example codes to understand millis function and scratching my head over and over. I wish i had found this video earlier...
@programmingelectronics
@programmingelectronics 4 года назад
Glad it helped!
@vjdav6872
@vjdav6872 4 года назад
Very clear explanation - I like that. I have taught some stuff in my one past life...Good job!
@martinest9458
@martinest9458 4 года назад
what a Legend ! i wish i would of found your videos earlier! Absolutely the best explanation of things. Thank you Sir!
@programmingelectronics
@programmingelectronics 4 года назад
Thanks a ton! Glad they were helpful.
@epartsacc
@epartsacc 2 года назад
This is the best "millis()" tutorial I have ever seen. Thanks so much for explaining everything clearly.
@programmingelectronics
@programmingelectronics 2 года назад
Glad it was helpful! Thanks so much for the note!
@omkarkhade4602
@omkarkhade4602 3 года назад
You are my favourite teacher. Thanks a bunch 😀
@guidoramacciotti3503
@guidoramacciotti3503 4 года назад
Very clear and simple explanation . Thank you!!
@AbhishekKanti
@AbhishekKanti Год назад
Thanks a lot man! I watched numerous videos, but wasn't able understand the concept of space time along with black holes. But now I'm confident enough to derive E=mc².💪
@programmingelectronics
@programmingelectronics Год назад
Glad it helped :)
@wmrieker
@wmrieker Месяц назад
I like that the if statement works even when the counter overflows so it'll keep going after 49 days and not miss a beat.
@amirmatrix9134
@amirmatrix9134 2 года назад
When you saved me I really love that tutorial it's actually the best thing I've ever watched in the history of our doing it Tori old and I'm not even being hilarious that's the truth thanks man keep up the good work !
@johnrees44..G4EIJ
@johnrees44..G4EIJ 4 года назад
I'm an 'old timer', and after a year of struggling with the theory and even the basic concept of 'millis', I've finally 'got it'! Thank you for the best Arduino 'millis' tutorial, and it's been my good fortune to find it..I look forward to watching more of your videos in future. John.. Bristol.. UK
@programmingelectronics
@programmingelectronics 4 года назад
Excellent! Great to hear John!
@ahmedessam9092
@ahmedessam9092 2 года назад
You make everything look simple . Thanks
@programmingelectronics
@programmingelectronics 2 года назад
I hope it helped! Timing stuff can get confusing quick!
@jandobbelsteen8953
@jandobbelsteen8953 5 лет назад
The way you show it will usually work nicely. However, the interval at which you trigger your event will be at least eventInterval, but often just a little bit longer. This is because the loop also takes a little time. Sometimes you may want to be more sure that you always trigger your timed event at an 'exact' multiple of 'eventInterval'. In such cases it's better to update your 'previousTime' with the 'eventInterval', like so: previousTime = previousTime + eventInterval;
@programmingelectronics
@programmingelectronics 5 лет назад
That's a fantastic point - thanks for that adding that Jan!
@naboulsikhalid7763
@naboulsikhalid7763 4 года назад
Great. first time explained, first-time understood. thank you very much
@programmingelectronics
@programmingelectronics 4 года назад
Awesome!
@conversationwithgod272
@conversationwithgod272 4 года назад
Really a great video.great people behind this Job...The visuals make everything so simple.thanks millions
@programmingelectronics
@programmingelectronics 4 года назад
Really appreciate that! Thanks!
@ChadKapper
@ChadKapper 2 года назад
These lessons are so well done!!
@programmingelectronics
@programmingelectronics 2 года назад
Thanks so much Chad - really appreciate that!
@georgemugala4830
@georgemugala4830 2 года назад
Best explanation ever on millis. Thanks alot bro
@programmingelectronics
@programmingelectronics 2 года назад
Thanks! Glad it helped!
@jackmini1217
@jackmini1217 2 года назад
enjoying this lessons. motivated to keep moving further. thanks a bunch.
@programmingelectronics
@programmingelectronics 2 года назад
Great to hear!
@AerialPhotogGuy
@AerialPhotogGuy 5 лет назад
Very Cool!! You come out with this video just in time for me to use millis() to toggle between volts and amps on an OLED display (without using delays, delays that long when added up would have made the loop way too long for this project). It took me a bit to figure out how to write the second section (like this:) (currentTime - previousTime >= interval + interval_1) I added the second interval time so I could set the volts code to display less time than the amps code since that's the one that needs to be read the most, but I got it. I'm sure I will eventually figure out an easier way but it's good for now and I'm proud of it! :-D The most valuable information in your video series is the fact that the timer continues to count up until the microcontroller is reset or turned off and on again. I now also realize that I can run more than one program from the same millis() function. It's kind of like calculating what needs to happen at different times of the day with a certain amount of time for each task. Yeah, I know, probably a screwed up analogy but there it is LOL :-) Until now I thought that the timer reset each time it was called for. Thanks!! Joe
@programmingelectronics
@programmingelectronics 5 лет назад
Thanks also for sharing your addition on the code - very cool!
@ruwansamanpriya6085
@ruwansamanpriya6085 5 лет назад
Wow.. That was the greatest tutorial I have ever seen on youtube...Thank you...
@programmingelectronics
@programmingelectronics 5 лет назад
Glad you enjoyed it!
@jameskalenga7546
@jameskalenga7546 3 года назад
😄 The millis code was smart. I love that logic
@kashpatel898
@kashpatel898 2 года назад
Excellent explanation and coding, with great visuals 👏
@programmingelectronics
@programmingelectronics 2 года назад
Thanks so much!
@jesus2639
@jesus2639 5 лет назад
Thanks you make it so easy to learn
@programmingelectronics
@programmingelectronics 5 лет назад
Thanks - much appreciated!
@VasilisKarastergios
@VasilisKarastergios 5 лет назад
You are awesome, I can't wait for the next video! 👍👍
@programmingelectronics
@programmingelectronics 5 лет назад
Thanks!
@anitaobiorah4661
@anitaobiorah4661 7 месяцев назад
I found your video very helpful. Thank you!
@programmingelectronics
@programmingelectronics 7 месяцев назад
Thanks so much for watching Anita!
@mohamedsoftline1
@mohamedsoftline1 4 года назад
This is a great explanation.
@NCVluminati
@NCVluminati 2 месяца назад
thankyou, I needed this
@ChandanKumar-kr2kj
@ChandanKumar-kr2kj 2 года назад
Great video. Thanks a lot for making this video.
@programmingelectronics
@programmingelectronics 2 года назад
Thank you! Thanks so much for watching!
@madhukeshnp
@madhukeshnp 4 года назад
The best explanation ever... the carrot example was just epic... every noob can understand..... thank you so much for the great tutorial.
@programmingelectronics
@programmingelectronics 4 года назад
Glad it helped!
@husseinnejah5337
@husseinnejah5337 4 года назад
this is legendary! massive Thanks
@programmingelectronics
@programmingelectronics 4 года назад
Thanks!
@philipeanthonybattung3860
@philipeanthonybattung3860 2 года назад
Oh you did great. This will help me on the annoying issue between RF transmitter not sending data because pulse sensor eats all the event
@programmingelectronics
@programmingelectronics 2 года назад
Great! Glad it helped!
@hamouz718
@hamouz718 4 года назад
Very entertaining channel, love your videos, keep them coming
@programmingelectronics
@programmingelectronics 4 года назад
Thanks - much appreciated!
@pedrofelipebezerra4491
@pedrofelipebezerra4491 3 года назад
The best explanation I've ever seen about millis()
@P44L
@P44L 2 года назад
true
@reylepiten3722
@reylepiten3722 3 года назад
Thanks for this great explanation..it really helps a lot...
@RamyHelmy-vv3gq
@RamyHelmy-vv3gq 2 года назад
You really have easily way to explain each point,thanks
@programmingelectronics
@programmingelectronics 2 года назад
Thank you! I hope it helped!
@mlggeek1812
@mlggeek1812 5 лет назад
Great video! Going to implement it to my project ASAP
@programmingelectronics
@programmingelectronics 5 лет назад
Thank you! I am glad it helped - best of luck!
@Khan_Rahman
@Khan_Rahman 3 года назад
why cant every tutorial be like this. Love it best
@P44L
@P44L 2 года назад
Very nice and easy to understand video, thanks!
@programmingelectronics
@programmingelectronics 2 года назад
Thanks for watching!
@hobarey5029
@hobarey5029 4 года назад
the best tutorial on millis() ever... thanks...
@programmingelectronics
@programmingelectronics 4 года назад
Thank you!
@johnmitchell4836
@johnmitchell4836 4 года назад
I think Micheal is THE BEST TRAINER out there to learn the basics of programming in Arduino!!! I've spent many hours watching all kinds of Arduino videos before I found Micheal's - Programming Electronics Academy. I signed up and watched ALL of his videos and it was well worth the money!!! I highly recommend it to anyone that is getting into Arduino programming. He is really, really good!!!
@programmingelectronics
@programmingelectronics 4 года назад
Thanks so much for the kind words John! I am glad you are finding the training helpful!
@emmanuelegel21
@emmanuelegel21 4 года назад
This is awesome! the best explanation ever about millis function. Thanks a lot... Poor millis can't catch the carrot XD
@rupert274
@rupert274 2 года назад
You're mean, Emmanuel!
@michaelg6327
@michaelg6327 2 года назад
GOD BLESS YOU! You saved me from days of suffering! You are my Hero!!!
@programmingelectronics
@programmingelectronics 2 года назад
Glad it helped!
@omkarbansode6305
@omkarbansode6305 5 месяцев назад
thankyou so much ,it was a really big help
@programmingelectronics
@programmingelectronics 5 месяцев назад
Great to hear!
@maxabeles
@maxabeles 3 года назад
Simply grand.
@adadmohamedcherif192
@adadmohamedcherif192 3 года назад
Thanks, very clear
@Val-eq4sg
@Val-eq4sg 5 лет назад
Muchas gracias, At last someone took the time to explain this, I really needed it thank you kind GOD of code..
@programmingelectronics
@programmingelectronics 5 лет назад
Glad it helped!
@dezmach93
@dezmach93 Год назад
Wow, you're the best!!! thanks!
@simplyjust-6912
@simplyjust-6912 2 года назад
Tyyyy this was such a good video 😄
@programmingelectronics
@programmingelectronics 2 года назад
Glad you liked it!! Thanks so much for watching!
@gamersglitch1922
@gamersglitch1922 Месяц назад
Great explanation sir thank you 😁❤
@Bianchi77
@Bianchi77 8 месяцев назад
Nice info, well done, thanks for sharing it :)
@programmingelectronics
@programmingelectronics 8 месяцев назад
Thanks for watching!
@sainumkhey8849
@sainumkhey8849 Год назад
the best explain tutorial lesson thanks a lot 👍
@hobarey5029
@hobarey5029 5 лет назад
very informative...thanks a lot...
@katrinejensrud537
@katrinejensrud537 4 года назад
fantastic video!thank you!
@programmingelectronics
@programmingelectronics 4 года назад
Thanks for watching!
@andrasparanici5491
@andrasparanici5491 3 года назад
The best lesson!
@fullbridgerecrifier
@fullbridgerecrifier Месяц назад
Thank you, That saved my life ❤
@programmingelectronics
@programmingelectronics Месяц назад
Glad it helped!
@plugnugget3672
@plugnugget3672 Год назад
Smoooth animation bro. I love the homey type design, backdrop is really chill. Casually printing ice ice bb to the serial monitor lol. Explained it fantstic with the carrot comparison. Sending money but more importantly encouragment. Your great at this! keep going - seriously God Bless ;) - J. T
@programmingelectronics
@programmingelectronics Год назад
Appreciate that - thanks for your generosity J.T.!
@mridulsarkar9015
@mridulsarkar9015 3 года назад
Very nice explaination. Thanks
@programmingelectronics
@programmingelectronics 3 года назад
Glad you liked it! Thanks for watching!
@raafathabeeb6718
@raafathabeeb6718 3 года назад
It was very useful information thanks
@programmingelectronics
@programmingelectronics 3 года назад
Glad it was helpful!
@lmatrix6626
@lmatrix6626 3 года назад
I think this is good idea if you need to step multiple stepper motors at the same time. When using delay() for moving stepper motors you can only move one stepper motor at a time
@HARSH9909
@HARSH9909 3 года назад
Such a nice video 🙂
@lindsaydempsey5683
@lindsaydempsey5683 3 года назад
Great video, thank you. Question, will that code work correctly when millis() overflows and starts counting up from zero?
@CommenterTheMan
@CommenterTheMan 3 года назад
This is very informative
@programmingelectronics
@programmingelectronics 3 года назад
Glad it was helpful!
@muhammadbilal2000
@muhammadbilal2000 3 года назад
Sweet explanation :) Thank you
@programmingelectronics
@programmingelectronics 3 года назад
Glad it was helpful! Thanks for watching!
@ankushchauhan5752
@ankushchauhan5752 3 года назад
Thank you sir i really appreciate that....😎😎
@Le0mach
@Le0mach 2 года назад
Hi! I'd like to thank you very much for the excelent explanation! I was struggling a bit with millis() until watched you videos. It saved me a lot of time and helped me to understand why my project wasn't working (that's the best way to learn something, by fixing it's bugs)! Keep on doing this awesome job, man!
@programmingelectronics
@programmingelectronics 2 года назад
Thanks so much for the note Leonardo!
@Simoooooooonn
@Simoooooooonn 3 года назад
Great video
@programmingelectronics
@programmingelectronics 3 года назад
Thanks!
@yuriu8
@yuriu8 3 года назад
Wow mate thanks it amazing lessons
@romycruz4498
@romycruz4498 3 года назад
wow that's awesome and well explained ! The presentation is very nice and clean and understandable ! but... what is it again ? ah, needs to rewind this utube vlog again & again.
@punjabilog
@punjabilog 4 года назад
Thank you very much Sir... Great Video
@programmingelectronics
@programmingelectronics 4 года назад
Thanks!
@ludionieves5494
@ludionieves5494 2 года назад
First off, thank you for your very informative video. I know this video is a few years old but I just came across it so my apologies for such a late comment. From your video, and from others, I understand that millis() starts as soon as the Arduino starts running and it keeps running, and increasing, as long as the Arduino is up, at least until it reaches its maximum value and restarts. I'm not sure that you actually CAN reset millis() from within code but everyone seems to say you shouldn't. Apparently doing so can break some libraries that rely on it. In order to understand millis() better I made a little project using code similar to yours to blink the built-in LED on and off at a preset interval while displaying current_elapsed_time (read from millis()) and previous_time, something similar to what you did in your code, and everything ran as expected. However, I noticed that every time I closed the serial monitor and reopened it the current_elapsed_time, which should display the current millis() value, returned to its starting value. The LED continues to blink at the proper interval while the monitor is closed, so I know the code is still running properly. Thinking there was a bug in my code I created a new, stripped-down program which only makes a call to millis() and prints the retrieved value to the serial monitor (see code below) and ran my test again. Same behavior. The code calls for the millis() value to be sent to the serial monitor directly - no massaging or assigning to a variable - and every time I close and reopen the serial monitor it appears to reset millis(). Not sure what is happening. Here is the simplified code I used to test: void setup() { Serial.begin(115200); } void loop() { Serial.println(millis()); } The program runs as expected and, as you can see, there is nothing but the call to print the current value of millis() but millis() seems to be affected by the status of the serial monitor window. Is this normal? Am I missing something? 🤔 Appreciate your help on this. Thank you.
@umiturgutaswwsa
@umiturgutaswwsa 3 года назад
What a great video.
@programmingelectronics
@programmingelectronics 3 года назад
Thank you! I hope it helped!
@Technologic1993
@Technologic1993 5 лет назад
Thank you so much!
@martinsiolowosoran5242
@martinsiolowosoran5242 4 года назад
very interesting, a good teacher
@programmingelectronics
@programmingelectronics 4 года назад
Thank you!
@lucienramono
@lucienramono 3 года назад
so nicely explain thank you :)
@programmingelectronics
@programmingelectronics 3 года назад
Thanks for watching!
@vasha1548
@vasha1548 3 года назад
love it
@Krystino
@Krystino Год назад
Amazing explanation, great thanks. Thus, there is something I don't manage to understand. If I want a start point not equal to the interval, I mean for example an event to start at 30 seconds, and to be repeated 60 seconds later on. Do I need one more variable to be created? Kind regards.
@JeThKo_MSW
@JeThKo_MSW 3 года назад
it was taking me forever to figure out why mine wasn't working, then i found out i had "==" instead of ">=" lol thanks for the very clear and concise explanation!
@programmingelectronics
@programmingelectronics 3 года назад
Thanks a ton for watching - I am glad it helped!
@attalaw36
@attalaw36 4 года назад
thank you
@lalogarcia6686
@lalogarcia6686 2 года назад
great video!!
@programmingelectronics
@programmingelectronics 2 года назад
Thank you!! If there are other types of videos you would like to see, I'd love to get your advice/feedback/recommendations Lalo!
@karanparve1734
@karanparve1734 4 года назад
wow its amazing...
@programmingelectronics
@programmingelectronics 4 года назад
Thanks for watching!
@hanac5586
@hanac5586 3 года назад
Thank you so much 🤍 + extra points from ice ice baby
@soul-motionselby
@soul-motionselby Год назад
thank you very much
@brucesmith9144
@brucesmith9144 4 года назад
One thing that should be added to the code is a trap for when the value of the millis() function rolls over. Consider if your Arduino is being used on a long term basis exceeding the long int value maximum. The user would want a way to handle that condition and continue the event timer. One quick way would be to check if the new millis() time is less than the previous time then the event timer loop can be reset.
@Ruudrad
@Ruudrad 2 года назад
The way the code is written, by subtraction of unsigned longs, it compensates for roll over. No additional checks are needed.
@____________________________.x
I was just wondering about rollover
@wadebrewer7212
@wadebrewer7212 3 месяца назад
​@@Ruudrad please explain a bit please. Is it in the code in your face code or firmware side that you simply do not see. As in... If I am using millis to run a tachometer on an engine, and using that tach value to hold ignition on (interlock if you will, if RPM drops it cuts ignition) it will not get the math wrong in seeing the correct rpm? The long term use case here is; the arduino is going to be powered on indefinitely monitoring a signal from inverter to start generator. Once the inverter calls, the arduino will sequence and start the generator. I dont want the roll over to cause am issue with a tach calculation inadvertently shutting down the generator.
@Ruudrad
@Ruudrad 3 месяца назад
@@wadebrewer7212 I initially also thought roll over would cause problems, however if you use longs _and_ subtract the unsigned longs (holding the output of the millis() function and/or the millis() function itself) the calculation will also work when millis() rolls over (I.E. goes from almost its maximum to just over zero). Strange but true thanks to how subtraction works on a microprocessor, which is NOT exactly the same as mathematical subtraction.
@wadebrewer7212
@wadebrewer7212 3 месяца назад
@Ruudrad Thank you tons. I was about to start researching for a work around. The community around this stuff is pretty great. Every once in a while you get the tool that talks down or "why do you want to do that project"....because I can....and at least for now...I am allowed.....lol. Even in my situation....reading and counting every quarter or half second for revolutions....even if it did send a call to shut off the system, the cycles are so quick I don't think it would actually shut down. But...sounds is like it's non issue anyway. Again, thank you for the input and much appreciated.
@HETRM
@HETRM 3 года назад
extremely helpfull!!!
@programmingelectronics
@programmingelectronics 3 года назад
Glad it helped!
@yassirbenmessaoud4587
@yassirbenmessaoud4587 4 года назад
Very helpfull! , but how it looks when you have a Button with some conditions? Thanks!
@pixies4ever324
@pixies4ever324 5 месяцев назад
haha.. being mean with the carrot and millis() function. love it.
@programmingelectronics
@programmingelectronics 5 месяцев назад
Thanks so much for watching!!
@vamshikp.j.8592
@vamshikp.j.8592 2 месяца назад
amazing explanationnnnnn
@programmingelectronics
@programmingelectronics 2 месяца назад
Thanks!
@bl4ckd0n4ut2
@bl4ckd0n4ut2 2 года назад
Thanks mate
@programmingelectronics
@programmingelectronics 2 года назад
I hope it helped!
@kpro-ke5hd
@kpro-ke5hd 6 месяцев назад
That actually make sanse,Thanks for the vod.
@kpro-ke5hd
@kpro-ke5hd 6 месяцев назад
We dont have to crate a variable(previousTime) if we only wanna execuit the if once.but to update the timing we have to substract the (currentTime from the previousTime)
@HillsWorkbench
@HillsWorkbench 5 лет назад
This detail on the mills() function has been very helpful to me, explains why a program I wrote a few years ago doesn't quite work as expected.
@programmingelectronics
@programmingelectronics 5 лет назад
Awesome - I am glad it helped!
@callumjones5288
@callumjones5288 3 года назад
This is great! However, how could i for example programme an event to take readings of from a temperature sensor for 1 minute? do i use debounceDelay?
@airduino5484
@airduino5484 2 года назад
fantastic
@programmingelectronics
@programmingelectronics 2 года назад
Thanks a ton for the note!
@stevenstraker5105
@stevenstraker5105 2 года назад
Great video, thanks! One comment though, I think we could also use a modulus operator to manage the event intervals. This would also cause it to run at millis() == 0, but we can use an additional clause to limit this. Perhaps something like: if( currentTime > 0 && currentTime % eventInterval == 0 ) { ...
@stevenstraker5105
@stevenstraker5105 2 года назад
Actually, it seemed like this would work in theory, but there needs to be a buffer, as the code would run multiple times at each interval. I guess this is why the lastTime variable is introduced, so that we can ensure the code runs only once per interval. Makes sense - I stand corrected!
@peterchrien
@peterchrien Год назад
very nice video
@programmingelectronics
@programmingelectronics Год назад
Thanks Peter!
@shrikantnikam2426
@shrikantnikam2426 4 года назад
Is it possible to make delay function in separate tab and use millis single line command like delay? For make code more simpler
Далее
Arduino millis() function: 5+ things to consider
12:49
Просмотров 135 тыс.
Using tabs to organize code with the Arduino IDE
12:18
Optimizing Arduino Code: no setup(), no loop() ⛔
9:27
How to Use Millis to Master Arduino Multi-tasking
50:17