How to Use Millis to Master Arduino Multi-tasking

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 พ.ค. 2024
  • Discover how to take your Arduino projects to the next level with this essential guide to multitasking using the millis() function instead of delay(). Learn how to efficiently manage multiple tasks on your Arduino, even if the Arduino can only execute one line of code at a time.
    Arduino Millis Tutorial with Code ▶︎ racheldebarros.com/how-to-use...
    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
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @robertorusso3192
    @robertorusso3192 5 หลายเดือนก่อน +31

    Hi Rachel, i saw many tutorials about millis, but no one was clear and effective like yours! Thank you!

  • @jimjames7479
    @jimjames7479 4 หลายเดือนก่อน +17

    she is what we think a real teacher should be like. she is the best educator out there.

    • @barleyhopps
      @barleyhopps 4 หลายเดือนก่อน

      She reminds me of sex-ed teacher.

  • @bikobika7319
    @bikobika7319 3 หลายเดือนก่อน +6

    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

    • @RachelDeBarrosLive
      @RachelDeBarrosLive  3 หลายเดือนก่อน

      I have a lot of fun doing these and learn new things too. 😄

  • @petrosyrjala6908
    @petrosyrjala6908 3 หลายเดือนก่อน +4

    You are the best at teaching arduino. You are a really efficient and lively person to teach with good examples. Thank you!

  • @joebatista4306
    @joebatista4306 7 หลายเดือนก่อน +4

    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

  • @jansmit4628
    @jansmit4628 3 หลายเดือนก่อน +2

    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.

  • @Anointingify
    @Anointingify 3 หลายเดือนก่อน +4

    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.

    • @RachelDeBarrosLive
      @RachelDeBarrosLive  3 หลายเดือนก่อน +1

      You are so welcome! Let me know how you make out.

  • @JohnyRalte
    @JohnyRalte 5 หลายเดือนก่อน

    Thank you Rachel. Best explanation ever, especially int, long and unsigned long. Great video for curious beginners.

  • @janszal
    @janszal 9 หลายเดือนก่อน +3

    Great example, I was looking something like this for some time. Keep up the good work!

  • @jasongrayston7450
    @jasongrayston7450 4 หลายเดือนก่อน +1

    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!

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

    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.

  • @josepheccles9341
    @josepheccles9341 4 หลายเดือนก่อน +1

    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.

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

    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!

  • @toeterdetoet539
    @toeterdetoet539 6 หลายเดือนก่อน +1

    Forcably limiting myself to the technical questions. (I'm stunned)

  • @johnpfeffer1957
    @johnpfeffer1957 2 หลายเดือนก่อน

    You're a good instructor! I learned 2 new things yesterday & today.

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

    Oh my god, this video just saved me. I had a fading led that stopped working when the servo was added, and I could not figure out what went wrong. Your explanation of the servo library messing with pin 10 helped so much. The way you explain code structure is also very straightforward. Thank you

  • @tr-labs8320
    @tr-labs8320 7 หลายเดือนก่อน +2

    Thank you for teaching this important lessen. Just what I'm looking for in multi-tasking with Arduino.

  • @richardgoldston5922
    @richardgoldston5922 2 หลายเดือนก่อน

    Hi Rachel, I am a radio engineer and I have just come across your vid's and love them so much,

  • @killtrocity6857
    @killtrocity6857 3 หลายเดือนก่อน +3

    Now this is a teacher i could sleep with after learnings ardrino

  • @mrrgc74
    @mrrgc74 3 หลายเดือนก่อน

    I have been looking for something to create a set of boom gates for a model train layout soooo many thanks you have explained everything i needed to know.

  • @pingfway1455
    @pingfway1455 8 หลายเดือนก่อน +2

    It helps to me understand the millis() function better and thinking this may be a better solution for creating a multi-tasking for my agriculture system. A system to control the temperature and irrigation. Your cheering explanation made the presentation interesting and enjoyable. Thanks a lot.

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

    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

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

    I got my code pulse counting running with other set of code. Thank you❤🎉

  • @speakertoanimals
    @speakertoanimals 4 หลายเดือนก่อน

    Very Nice! Polling is incredibly useful, simple to code, and effective (as long as the processor works faster than the components.) You did a great presentation. BTW, I think your vid on using hardware interrupts (for the button) is a great way of kicking it up a notch.

  • @gigsim7115
    @gigsim7115 3 หลายเดือนก่อน +1

    I love the energie and the way you talk.

  • @DONCRAGUN
    @DONCRAGUN 3 หลายเดือนก่อน +1

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

  • @stradcar1
    @stradcar1 4 หลายเดือนก่อน

    This is the best present I have ever watched guaranteed not to make you sleep.

  • @flywittzbeats4008
    @flywittzbeats4008 2 หลายเดือนก่อน

    I am now a state machine master! Haha thank you so much this is amazing.

  • @rinkashime0289
    @rinkashime0289 4 หลายเดือนก่อน

    At the end about what you said on the servo library where there are certain pins that will not behave right when you use a servo library. It is new to me and that I have a previous project where I encountered such problem, I wasn't able to determine the problem. Now I know why, thanks Ma'am

  • @carrizzle9586
    @carrizzle9586 6 หลายเดือนก่อน

    Great video!!! Very detailed explanation of the Millis function and how to make use of multiple devices at once, kind of. Thanks for sharing.

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

    So glad I found this channel... Have you done a stepper motor video yet?

  • @markwerley6965
    @markwerley6965 4 หลายเดือนก่อน

    This was very well conceived and presented. A few years ago i built a Halloween Monster in a Box prop, and although I noodled my way through the coding, I would have benefited from this video. Nice work.

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

    Wow !..Just found your channel again, 👑 De Barros !..

  • @Steve-xb7dn
    @Steve-xb7dn 2 หลายเดือนก่อน

    Great video Rachel, love your energy and enthusiasm

  • @vermeirmarc2
    @vermeirmarc2 5 หลายเดือนก่อน

    Thanks a lot, helps me a lot! Clear explanation and good examples! Best regards, Marc

  • @stever3886
    @stever3886 4 หลายเดือนก่อน +2

    Hey Rachel, I snagged this note below from the Arduino reference page for analogWrite function. Your comment about some PWM pins being flakey made me do a little digging. In general pins 5 and 6 “may give” unexpected results?
    Notes and Warnings
    The PWM outputs generated on pins 5 and 6 will have higher-than-expected duty cycles. This is because of interactions with the millis() and delay() functions, which share the same internal timer used to generate those PWM outputs. This will be noticed mostly on low duty-cycle settings (e.g. 0 - 10) and may result in a value of 0 not fully turning off the output on pins 5 and 6.

    • @Samiby
      @Samiby 2 หลายเดือนก่อน

      I think UNO just needs to disappear. So many tech issues with it. For the cheaper price, people need to start buying into more functional esp32 boards or something

  • @beachcomberbob3496
    @beachcomberbob3496 2 หลายเดือนก่อน

    Now all we need to know is how we drop out of a void function once that function has reached a time limit (or number count). It would be cool to see the red LED turn off after 2 minutes, and/or switch on with a button, run for two minutes, stop again and wait for the next button press. Having said all that, your tutorials are crystal clear compared to a lot of guys on TH-cam who head off into the weeds.

  • @SaiksTech
    @SaiksTech 3 หลายเดือนก่อน +1

    You made the whole lesson enjoyable with a unique approach.
    Bless dear!

  • @SpectreTTM
    @SpectreTTM 6 หลายเดือนก่อน +2

    Loved the pacing of the coding. Too many times people go so fast and don't explain why they code things a certain way. It felt like we were included in the thought process of the code rather than just watching someone type in the code.
    Stumbled across this video looking for multi tasking on the Arduino for a Halloween prop. Thought it was a coding channel until I looked at your other vids. Pleasantly surprised to see the Halloween / props vids. Thx

  • @davidcamilleri288
    @davidcamilleri288 7 หลายเดือนก่อน +1

    Hi Rachel, thanks to you I can manage my project better now because I was going crazy trying to use three infrared object sensors at the same time but could not manage to do it. now i am going to have a try following your program and then we'll see the result.
    thanks again.

  • @mixme8655
    @mixme8655 6 หลายเดือนก่อน

    New subscriber I enjoy watching your videos thank you ❤ with sense of humor I learned a lot from you as beginner

  • @christophe1800
    @christophe1800 4 หลายเดือนก่อน

    If i could, i would have given this video more than 1 thumbs up. Very entertaining and instructive. Thanks.

  • @RocketCarpenter
    @RocketCarpenter 5 หลายเดือนก่อน +2

    You are just an amazing teacher!

  • @cyberwip
    @cyberwip 4 หลายเดือนก่อน +2

    You don't have to worry about unsigned word length, it wraps perfectly. CURRENT_TICS - LAST_TICS will always be the difference even if CURRENT_TICS wraps around and is less than the starting tic count. (The beauty of UNSIGNED math).

    • @bertblankenstein3738
      @bertblankenstein3738 4 หลายเดือนก่อน

      As long as you do not wrap more than once between taking values.

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

    This is seriously a great video. Hit my issue exactly !

  • @banglarif
    @banglarif 6 หลายเดือนก่อน +2

    You are 24k gold. I like the way you teach. WOW. OMG

  • @StaleCookies
    @StaleCookies 3 หลายเดือนก่อน

    Wow fantastic you are so engaging I learned a lot and at a manageable pace thankyou

  • @skipsmessyworkbench
    @skipsmessyworkbench 2 หลายเดือนก่อน

    Again...Excellent lesson!!! I've subscribed to you on both of my channels.

  • @rudyvlog2897
    @rudyvlog2897 6 หลายเดือนก่อน +1

    Wow thanks ma'am looking forward for more interesting tuitorials 🙂

  • @garciawallace7106
    @garciawallace7106 2 หลายเดือนก่อน

    Hi Rachel, Thank you for this awesome video, using millis function. I am working on a project display and i need to pause some warning banners when triggered by different sensor readings, but when i used delay function every freeze up and
    Sensor reading start lagging i didnt like it so had to get rid of the delays but then the banners wont show now. So i think this millis will fix my issue. Tried it before but i tried using it lik a delay() and now after watch you videos i see why it didnt work. Lol So thank you for these great videos it so easy to follow along i learn a lot from your vids.

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

    From malawi ,ur brilliant

  • @J_Creative
    @J_Creative 5 หลายเดือนก่อน

    Beauty with brain 🎉thank to this clear tutorial hope to have some more tutorials,,😊

  • @TheUnofficialMaker
    @TheUnofficialMaker 4 หลายเดือนก่อน

    Very clear and outstanding job of explaination with examples and code.

  • @dab3963
    @dab3963 2 หลายเดือนก่อน

    Great video, very clear explications I appreciated too much. I wonder how to solve in case of a button with 2 states and debouce problems without use of delay function

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

    thank you
    this was clear

  • @danieltugui4364
    @danieltugui4364 4 หลายเดือนก่อน

    extremly useful, thank you from italy

  • @mikey38632
    @mikey38632 3 หลายเดือนก่อน

    Thank you for this video, it is most timely. I am planning to use a microcontroller with similar capabilities to drive several LED status lights with various behaviors during various conditions, and this is likely the key to making it all work together properly.

    • @RachelDeBarrosLive
      @RachelDeBarrosLive  3 หลายเดือนก่อน

      Neato! Let me know how you make out!

  • @ayganotomasyon1109
    @ayganotomasyon1109 4 หลายเดือนก่อน

    Thank you. Very good sample code to understand millis..

  • @lidiaermolenko621
    @lidiaermolenko621 3 หลายเดือนก่อน

    Please, do not stop, this is best lessons, what i see. What do you thing about FLprog, for education Arduino?

  • @wisco58
    @wisco58 3 หลายเดือนก่อน

    super super interesting video's. Just one question. Do you have a video where you use a servo motor controlled by a joystick?

  • @vantondercorne
    @vantondercorne 2 หลายเดือนก่อน

    you are the best. Thank you🤗

  • @KeffelewAssefa
    @KeffelewAssefa 4 หลายเดือนก่อน

    Thank you, great tutorial.

  • @mdrafiqul3358
    @mdrafiqul3358 4 หลายเดือนก่อน

    Thank you very much good work, prayers and best wishes for everyone

  • @nara49veera12
    @nara49veera12 4 หลายเดือนก่อน

    Excellent delivery of key concepts. Awsum. It will help me more if you use larger fonts when you explain the code, Thanks in advance.

  • @sajiniwasana7869
    @sajiniwasana7869 5 หลายเดือนก่อน

    You are an amazing teacher 😍😍😍 thank you very much ❤

  • @DBB-KE5DUO
    @DBB-KE5DUO ปีที่แล้ว +2

    This is just like a Perl program i wrote many moons ago! i measured from the computer epoch to several "triggers" including one that sent an error email if the program seemed to be running away (but continued until another time frame passed by) ...
    😎😎😎😎😎😎😎😎😎😎

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

    I like your teaching...
    I come from C#, does Arduino have a "backgroundworker" function ?
    Where you can have two threads working at the same time ?

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

    You are wonderful. Great teacher and fun to too! ❤❤

  • @mixme8655
    @mixme8655 6 หลายเดือนก่อน

    Lively presented love it ❤

  • @cyberphox1
    @cyberphox1 4 หลายเดือนก่อน

    Really nice and engaging video. Subscribed

  • @SusanAmberBruce
    @SusanAmberBruce 4 หลายเดือนก่อน

    Brilliant tutorial thanks

  • @johnsun2416
    @johnsun2416 4 หลายเดือนก่อน

    Is there a way to use millis to create flashing light with independent off time on on time adjustments?

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

    Hi I've been trying to get a servo go to 180 when you seter press the button in position on don't know what I'm doing wrong have tried a little bit of everything but millis might work what do you think about it

  • @grk608
    @grk608 2 หลายเดือนก่อน

    Hi Rachel,
    So what if I wanted to use millis to blink the LED only once? I have several instances of millis I want to use but I want each one to do it at different times and only one time each. The delay function won't work because it blocks the other code from running that has to keep running. Thanks.

  • @damianbutterworth2434
    @damianbutterworth2434 14 วันที่ผ่านมา

    Hi Rachel, I been using a for n loop for years doing a similar thing. I`ll mix it with BBC BASIC because I`m drinking. :)
    FOR N=0 TO 2000
    IF N=1000 THEN LET LED=TRUE;
    IF N=1500 THEN LET LED=FALSE;
    DELAY(1);
    NEXT N

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

    Hi Racheal, how would I fade down the blue LED

  • @KJ7JHN
    @KJ7JHN 2 หลายเดือนก่อน

    Hi Rachel, do you have a video covering TCP/IP for DOS 6.22 or FreeDOS 1.3? I'm really looking for a guide on bridging 6.22 and HTML5? I think HTML5 is the most recent? I'm making a game that needs Network support. Thanks!

  • @fatihakalper9460
    @fatihakalper9460 3 หลายเดือนก่อน

    Hi Rachel, I loved your explanation. Can you create content about Modbus RTU communication on Arduino? I'm looking forward to your video.

  • @georgejetson4378
    @georgejetson4378 4 หลายเดือนก่อน

    Hi Rachel, Just stumbled upon your channel. What’s an Arduino?

  • @zilog-z80
    @zilog-z80 5 หลายเดือนก่อน +1

    Excelente muchas gracias

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

    Can i upload two functions first is - 20Khz PWM signal and
    Second is - millis function for timer.
    Will 20Khz program disturb millis program?

    • @hannescamitz8575
      @hannescamitz8575 4 หลายเดือนก่อน

      I havn't tried that with millis but it uses TMR1(16bit) and it depends how it is implemented.
      If you set up your own timer instead you can probably have two counters that increases and they can send interrupts to your program later.

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

      ​@@hannescamitz8575sorry but I don't understand what you said.
      I have two programs one is 20Khz PWM and second is Timer set program, individually both programs is proper worked. With Arduino UNO, if both programs upload in UNO board then timer program disturb. I think you understand, so please give me any solution if you had time.

  • @JelMain
    @JelMain 4 หลายเดือนก่อน

    You're reinventing the wheel, as seen in Windows 3. If you need true multitasking, you need multiple cores, and handshaking at points where Job A has to be complete before Job B resumes. A railway's a primitive example, Train A has to leave the station before Train B enters.

  • @toeterdetoet539
    @toeterdetoet539 6 หลายเดือนก่อน

    Could we also have 80MHz clockticks instead of millis ?

  • @SandeepSandhu
    @SandeepSandhu 3 หลายเดือนก่อน

    Brilliantly explained….👌🖖

  • @rickhunt3183
    @rickhunt3183 3 หลายเดือนก่อน

    Time slicing or super looping are probably more accurate terms than multitasking. While time slicing can be very useful. Sometimes It's best to divide a task among multiple microcontrollers working independently, and have a master controller monitor and control ( adjust ) each independent controller.

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

    I'm new in your channel. Excellents class. Your english is clear and expressive. Thank you

  • @davidgierke7582
    @davidgierke7582 3 หลายเดือนก่อน

    As a retired high school technology teacher who subsequently became the author of books concerning the internal combustion engine and pioneer flight. I am currently working on a series of books designed to meet the needs of middle grade kids who are interested machines from a hands-on perspective-a severely overlooked topic that is rarely addressed in middle school or high school library books. Book one (completed) is about an 11 year-old who is enthralled by the internal combustion engine and its systems. In book two, our protagonist desperately wants to learn how to code because he knows that modern engines depend upon ECMs (Engine Control Modules). Unfortunately, I wasn't having much success in my "coding research"-until I ran across your channel and watched two of your Ardiuno-assisted lessons. Wonderful-what a talent you are! I was not only impressed by your knowledge of coding, but also your ability to deliver a well-researched lesson plan! Your two "lessons" did more for me than a month's reading of two of the most current books on "coding for kids!" Please continue with these coding-centered lessons. PS-would you consider co-authoring book two?

  • @RandomTorok
    @RandomTorok 3 หลายเดือนก่อน

    Can we create a delay function, say myDelay(int) so if I call myDelay(30) it will pause for 30 seconds? Will have to read your writeup closely.

  • @jamesmoon5632
    @jamesmoon5632 29 วันที่ผ่านมา

    Great tutorial

  • @mikey38632
    @mikey38632 3 หลายเดือนก่อน

    At 18:00 I'm thinking you could probably do a
    ledState = !ledState
    But having the If statements is good when there are more things to be done based on the If's

    • @RachelDeBarrosLive
      @RachelDeBarrosLive  3 หลายเดือนก่อน

      Great idea! I'll have to try that out.

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

    You da best!!

  • @HenrikHvalpen
    @HenrikHvalpen 4 หลายเดือนก่อน

    I would like to see how you could make the 3 leds blink in a row.
    Like:
    Delay 3 seconds
    RedLED High for 500 ms
    Delay 3 Seconds
    BlueLED High for 500ms
    Delay 3 Seconds
    GreenLED High for 500ms
    While the servo is still going.

    • @MB-fp9lq
      @MB-fp9lq 3 หลายเดือนก่อน

      Guessing here but, what if you play with the original values, so like for red it's 6000, it waits for 9000 (and since it starts with 6000 it's only gonna wait for 3000), then it blinks. for the Blue give it 3000 initially, it waits for 9000 (so only 6000 the first time), and for the green initial value of 0, so it does wait for the full 9000ms. There might be a better way to do it but this is what I could come up right now.

  • @lookin4ward1
    @lookin4ward1 3 หลายเดือนก่อน

    This is great

  • @danny117hd
    @danny117hd 4 หลายเดือนก่อน

    Bool for high and low and the code becomes ledState = !ledState. 1 line versus 6

  • @billk7683
    @billk7683 4 หลายเดือนก่อน

    Thank you for the easy to follow presentation; I an using a NANO; maybe there is a compatibility problem ; the sketch gives error at line 9 > const unsigned long blinkperiod = 500 maybe someone can advise please

    • @billk7683
      @billk7683 3 หลายเดือนก่อน

      found solution
      line 20 > unsigned long currentMillis() = 0 ; //stores the current time
      should be unsigned long currentMillis = 0 ; //stores the current time
      did nobody else have this issue ;
      i copied and pasted from the printed tutorial
      Bill

  • @danny117hd
    @danny117hd 4 หลายเดือนก่อน

    Consider calculating the future time and the code execution is faster cause your not even doing the subtraction just the comparebe... if currentmissis > nextmillis. ( Nextmillis+= period; ledState=! ledState; digitalwrite(mled.ledstate).; ). Faster code = feel more responsive.

  • @larrys_truth
    @larrys_truth 5 หลายเดือนก่อน

    Hello Rachel;
    I connected 3 servos using the millis function.If I set the periods for all 3 servos it works fine.But if I set different periods they dont work.
    Am I doing something wrong? Thank You.

    • @PhilDennis
      @PhilDennis 4 หลายเดือนก่อน

      Make sure you have a separate set of variables for each servo, and aren’t accidentally using the wrong ones somewhere.

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

    Maybe it is in the text, but it is not commented in the code, or the explanation. For me the MOST important reason for using longint, is that with that logic if statement is protected for roll over. if ( millis() - servoPreviousMillis >= servoPeriod) will ALSO work if servoPreviousMillis is close to its max and millis is just over zero. I think that is too important not to mention explicitly, it is not common knowledge…

  • @Andygodin
    @Andygodin 4 หลายเดือนก่อน

    The question from arduino novice, can I use "#define pin" instead of "int pin" define in the very top of the scetch? And how it affect the code afterwards?

    • @jonathanlin9772
      @jonathanlin9772 4 หลายเดือนก่อน

      It will affect the generated machine code, which may be faster/slower or of a different size depending on the target processor.

    • @engrtiocs
      @engrtiocs 3 หลายเดือนก่อน

      By using #define, the compiler places the value in program memory rather than in RAM. Though it would still work either way, its good practice to define unchanging values like pin numbers as constants just to save RAM.

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

    help me lot