How to Use Millis to Master Arduino Multi-tasking
45,952
Publicado 2023-04-17
Arduino Millis Tutorial with Code ▶︎ racheldebarros.com/how-to-use-millis-arduino-multi…
In this tutorial, we'll cover:
1. The limitations of using delay() and why millis() is a game changer for Arduino multitasking.
2. Practical examples and step-by-step instructions to replace delay() with millis() in your projects.
3. How to create non-blocking code to handle concurrent tasks more effectively.
4. The benefits of implementing state machines to manage independent tasks simultaneously.
Whether you're a beginner or an experienced Arduino enthusiast, this video will provide you with valuable insights and techniques to enhance your projects' responsiveness and complexity. Don't miss out on unlocking the full potential of your Arduino microcontroller.
Video Chapters:
0:00 Intro
0:42 Limitations with Using Delays
1:24 What is Millis?
1:56 How Long Can Millis Count?
2:43 What Does Millis Look Like?
5:00 Circuit Diagram
5:47 Blink the Red LED: Understanding your first millis() sketch
22:15 Add a Fading Blue LED
30:34 Add a Push Button Toggling Green LED
36:44 Add a Sweeping Servo
45:20 Servo Library Conflicts
49:07 Wrap Up & Final Thoughts
Build & Code Along:
🛒 Arduino Uno or Clone: amzn.to/476UQIB
🛒 Breadboard: amzn.to/497qA1V
🛒 Jumper Wires: amzn.to/3tSo3Zd
🛒 LEDs: amzn.to/46IWArx
🛒 330 Ohm Resistors (or resistor kit): amzn.to/492V3OB
🛒 Push Button: amzn.to/407vuIa
🛒 Micro Servo: amzn.to/40fUyNm
Join the Engineering Artists Community ▶︎ racheldebarros.com/community
Some links included here are to affiliate sites. If you purchase something through them, I may earn a small commission — which costs you nothing! I am very grateful for your support when you use my links to make a purchase.
#arduinotutorial #arduinomillis #arduino #millis
Todos los comentarios (21)
-
Hi Rachel, i saw many tutorials about millis, but no one was clear and effective like yours! Thank you!
-
she is what we think a real teacher should be like. she is the best educator out there.
-
Hi Rachel I am not only an arduino learner, but I am also an english learner So I think I am lucky when I watch your videos because your clear accent and your explanation way Thanks
-
Hi Rachel, so glad i came across your channel, your presentation is so much more vibrant and intuative than others (i guess we learn better/ easier when we having fun). Will follow for all things arduino/ coding
-
You are the best at teaching arduino. You are a really efficient and lively person to teach with good examples. Thank you!
-
Great example, I was looking something like this for some time. Keep up the good work!
-
Hi Rachel, I want to say your illustration of using millis with all in one example was just awesome. Your detailed example gave me a good understanding of this topic. Thank you very much.
-
Thank you Rachel. Best explanation ever, especially int, long and unsigned long. Great video for curious beginners.
-
You are an entertaining and enthusiastic teacher. Found a small error I think in the servopos values which is declared as an integer. While incrementing its value it will run upto 181 before it decrements again. The servo will not run past 180 so will be there for 2 intervals. As servopos is declared as integer, it can become -1, which creates the same situation in the opposite position. In your demo nobody can see this, but when you really drive something serious with the servo you would notice. Your energy makes me want to pull the arduino out the drawer and play with it some more. Keep up your teaching sessions.
-
Hi Rachel. Thank you for posting such a great tutorial video. Have recently got back into Arduino programming with a view to controlling a model railway and associated accessories such as signals, uncoupling ramps and turnouts (or points as we call them here in the UK). This video is going to help me a lot! Loved the fact that you just dealt with syntax errors as they came up, those darned brackets get me every time too! And thanks for the tip about the servo library pin conflict, that was news to me. Great work!
-
I teach high school robotics in Canada. You are a fantastic teacher! My kids are going to love the way you explain coding. I have a bunch of girls in my program who will be looking up to you as well! Thank you so much!
-
Thank you for teaching this important lessen. Just what I'm looking for in multi-tasking with Arduino.
-
Amazing! You're amazing with all that knowledge of configuring the functionality! Rated highest in my class when in college making me pretty much a good for it geick! Really injoy the jargon! Looking bright, brilliant and a natrual at it!
-
You made the whole lesson enjoyable with a unique approach. Bless dear!
-
You are so much fun to watch. I have taken up using a library "elapsed millis" for many similar tasks. I started using that when I made an NHRA style Christmas tree like starts drag races. I use a single object to compare to for turning on and off each light. Before I was using industrial PLC's to make them, but those are expensive. But I have a lot more experience writing programs for those. Ladder logic is a lot more simple to write than C, or the similar found in arduino.
-
Hi Rachel. I really like your teaching style. The energy and enthusiasm are infectious. I wish I had had computer science teachers with your skills when I was learning to program 50+ years ago. However, I think the range of values written to your servo are a little bit out of range. If servoIncrement is 5, your code would give values from 185 to -5 inclusive to the servo.write method. Shouldn't you have something more like: servoPos += servoIncrement; if((servoPos > 180) || (servoPos < 0)) { servoIncrement = -servoIncrement; servoPos += 2 * servoIncrement; } servo.write(servoPos); or: if((servoPos + servoIncrement > 180) || (servoPos + servoIncrement < 0)) { servoIncrement = -servoIncrement; } servoPos += servoIncrement; servo.write(servoPos);
-
What and absolutely fantastic teacher you are Rachel.. it helps no end to see someone explain as they write the code and describe their thought process .. just wonderful. Never subscribed so fast and eager to learn more
-
Hi Rachel, I am a radio engineer and I have just come across your vid's and love them so much,
-
Great video. I have always stayed away from millis mostly as it can get so complicated, but you make it look easy. I will have to try this again.
-
You're a good instructor! I learned 2 new things yesterday & today.