How to Use Arduino Interrupts The Easy Way

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 พ.ค. 2024
  • Have you ever wanted to take advantage of Arduino hardware and software interrupts but didn't know how? In this tutorial, I'll show you the basics of using an Arduino's interrupts the easy way - quickly setting up the pins and handling events with just a few lines of code. Implementing software or hardware interrupts can open up a world of possibilities for your robotic creations - adding an extra layer of sophistication that takes your Arduino project to the next level. So dive in and let's discover how we can harness the power of Arduino interrupts for our own projects!
    Arduino Interrupts Tutorial with Code ▶︎ racheldebarros.com/how-to-use...
    Download TimerOne Library: playground.arduino.cc/Code/Ti...
    Video Chapters:
    0:00 Intro
    1:04 Example Without Interrupts
    7:26 Hardware Interrupts
    20:00 Software Interrupts (with TimerOne library)
    31:54 Wrap Up
    Build & Code Along:
    🛒 Arduino Uno or Clone: amzn.to/3MdxwRt
    🛒 Breadboard: amzn.to/3MgbzkG
    🛒 Jumper Wires: amzn.to/473kmON
    🛒 LEDs: amzn.to/3FvqV0U
    🛒 330 Ohm Resistors (or resistor kit): amzn.to/46TEZgm
    🛒 Push Button: amzn.to/45IuETs
    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 #arduinointerrupts #arduino #interrupts
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @ZothiamaCF
    @ZothiamaCF 2 หลายเดือนก่อน +11

    5 minutes in to the video and I've already clicked the subscribe and like buttons. This is how all tutorials should be made. You are a most awesome teacher.

    • @Nemecys
      @Nemecys 4 วันที่ผ่านมา

      Exactly what this guy said - sooooooooooo beautifully explained :)

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

    Easily the best Arduino tutorials I’ve seen on TH-cam. I came for the interrupts, but I will definitely be watching more. A refreshing change from the usual content. Thank you!

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

    You are one fantastic teacher! I am a former HP engineer (long ago!) and have finally reached a place in life where I can do this sort of thing just for fun.
    Your videos are immensely helpful and entertaining to boot. Absolute goldmine.
    Thanks for all that you do!

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

    Great video, you explained this so well! I've spent hours looking at other videos on timers and interrupts which just confused me. I'm just getting back into Arduino programming after a 5-year break, and this was a huge help with the project I'm working on.

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

    Really good, straight to the point and simple. Exactly what I need for my projects

  • @ChaplainDaveSparks
    @ChaplainDaveSparks 2 วันที่ผ่านมา

    I love this video for two different reasons:
    I haven’t programmed interrupts in ages. If I’m not mistaken, it was on a Z-80 back in the 80s.
    Rachel reminds me so much of someone we lost, also in the 80s: *_Karen Carpenter!_* Similar voice, facial expressions, and body language.

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

    It's refreshing to hear code explained with such enthusiasm!

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

    This is brilliant, for a 65 year old to finally understand how interupts work. Your upbeat way of describing how it works is just fantastic. I can now implement this in a few of my projects and also see if I can find information on doing a similar thing with the ESP32 to improve some of those projects. Thanks Rachel, I will certainly go through your videos and also subscribe. Regards, Geoff.

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

    ..i like the flow of this tuturial...its like a sketch itself...it delivers you from darkness to light...

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

    Your descriptions are clear and enjoyable to watch. I didn’t yawn at all and no urge to nap which is common with the monotone streams I have endured. Showing the pitfalls and showing the process . Thank you for your stream.

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

      I have also napped through many explanations 🤣

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

    EXCELLENT description of using interrupts. Very Good!!!

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

    Great video. Might be worth mentioning a while loop with small 1ms delay as a non interrupt solution on the way to the interrupt solution. Also an internal timer is a hardware interrupt, software interrupts are generated directly by the microprocessor when it needs system tasks done - memory management, errors, crashes, etc

  • @zuzukouzina-original
    @zuzukouzina-original 2 หลายเดือนก่อน +1

    You have a gift to explain it very clear and simple. Thank you 🙏🏼

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

    Great video. Rachel's infectious enthusiasm had me hitting subscribe right away.

  • @vladimirastrelin1719
    @vladimirastrelin1719 2 หลายเดือนก่อน +1

    What an amazing lesson! Very clear ! Just a pure pleasure to listen, watch and follow your instructions. Thank you very much !

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

    I built a demonstration of a perpetual motion machine as my first project using an Arduino. "Perpetual Motion Machine?" The Arduino is very flexible and can even work with a power supply that is a half bridge rectifier. Looking forward to your next video.

  • @miachristensen5444
    @miachristensen5444 4 หลายเดือนก่อน +10

    This is so incredibly easy to understand and paced at such a great rate! Thanks for the amazing video! Can't wait to learn more from you =)

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

      Glad it was helpful! Let me know if you want me to cover any topics and I'll put it in rotation.

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

    This was really well explained!

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

    Your knowledge is excellent. Thank you for sharing. Big Hats off.

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

    Thank you for this very inspiring and informative video.

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

    Very usefull explanations! Ty very much. Blessings from Spain 🇪🇸

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

    Thanks from the Netherlands 🇳🇱 for your super tutorial! Your videos are very helpfull! 😊

  • @sennabullet
    @sennabullet 25 วันที่ผ่านมา

    Thank you for this video. I really appreciate your enthusiasm!

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

    I'm new to arduino and programming. I thought that this video was fantastic, thank you. Liked and subscribed!

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

    I have to confirm previous comments, you are a great teacher and the best and demonstrating Arduino IDE.

  • @rhandynastor4866
    @rhandynastor4866 9 หลายเดือนก่อน +1

    thanks for this. Very nice explanation

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

    Very well explained and helps a lot of thanks.

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

    Wow great video. Well presented. Easy to understand.
    Learning arduino and found this excellent.

  • @husky-nu3xk
    @husky-nu3xk 15 วันที่ผ่านมา

    Best explanation ever. Thx Rachel

  • @Richardson_Valakyr
    @Richardson_Valakyr 8 วันที่ผ่านมา

    Im learning english and also Arduino... i found both here you are amazing... Thanks!!!!

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

    Cool.. arduino beginner should watch this.. I'm sharing it to classmate..

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

    love your energy and enthousiasm ;-)

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

    Great video. Enjoyable and informative.

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

    You are my new favorite teacher

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

    I almost want to duplicate the previous comment excellent explanation so pleased I found this channel
    Thank you

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

    Awesome video thanks! Ive been having trouble reading the pulses from an old school rotary dialer using just debouncing, I think this will do the trick for me though!

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

    This was awesome. Going to check out the rest of your Arduino vids. Thank you so much for posting this. Really appreciate it =)

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

      Thanks! Let me know if you'd like to see any specific topics.

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

    Good video :) You're clear in your explanations.
    Here are some video ideas. Id love to see a video about threading or on some more basic stuff like interpretation of the pinouts, how to look to get to know how a new component works (what things to look into)... Stuff that give users more independance

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

    Great video!, thank you .

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

    Good video, informative and well explained. I have subscribed.

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

    Wow, what a great teacher. So enthusiastic!. Good examples. Now I can fix some broken ISRs that use sleep.

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

    interrupting my viewing to say this: Amazing, so clear and helping so much. Not even finished the video yet and its already heaps helpful, thanks!

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

      I'm glad to hear the vid is helping you out! Let me know if you'd like me to cover any other topics!

  • @user-lk4bq5uk9v
    @user-lk4bq5uk9v หลายเดือนก่อน +2

    The world's best Queen teacher thanks

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

      Glad you enjoyed it! Let me know if there's any topics you'd like me to cover.

  • @ms070965
    @ms070965 20 วันที่ผ่านมา

    Very Well explained. Thx a lot

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

    Thanks for sharing

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

    Thank you!

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

    Thank you for this very, very helpful tutorial! it wooooorrrrrrrkkkssssss :)

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

    I agree with the ones saying that you are a great instructor. I'm also retired, but I'm making and programming robots.

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

    I remote controlled a 10 HP Craftsman track drive snow blower using a 10 channel Flysky and mega 2560. I learned Arduino coding just to build the project. I use all 10 channels to operate the servos, motors and actuators. I was able to get everything to work without using any interrupts. I'm sure my code is far from perfect, but surprisingly I got everything to function.

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

    Thank you so much.

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

    Thank you, it is a well informed video 😊.

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

    Good Teacher !
    Easy on the eyes too ☺

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

      My problem is, when I should be looking at the code, I'm looking elsewhere...!

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

    Thank you for this. My project involves LaRa radios remotely located, so this is a big boost in being able to run the remote processes while waiting to receive a transmission.
    One difference from your video. When I run your sketch, exactly copied, RED flashes four times, the BLUE flashes, but twice, in opposite synch to RED. Then red flashes twice more, then blue-red twice, etc. I've played with the delay and the microseonds. Seems as though the ISR runs twice every 1/10 second. I'd like to test LoRa for data receipt in the interrupt and do pass the incoming data to the loop. It may not matter, but thought I'd ask since my results differ. Thank you again.

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

    i watch so may videos on google related to interrupt , but your lecture is amazing, i understand all the concept very clearythanku so much , for a grt video😁😁

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

      Glad you enjoyed it! Let me know if you want to see any other topics.

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

    At 3:15 you asked if anyone had figured out how to do this without interrupts. Just build a state machine into the loop() code. Let's say you want to update the button every 50 mS. {20 times a second}. You have two tasks to accomplish (update the red LED and update the button), so loop() has to run every 25 mS. In setup(), add stored_millis = millis(); {along with all the other bits.}. Inside loop() write a while loop that reads the latest value of millis() and compares it to stored_millis(), If greater than 25 mS, break out of the while loop. Next, stored_millis = latest_millis; state_counter += 1; If state_counter is odd, call Update_Red() else call Update_Blue(). In Update_Red(): increment a variable red_counter. If red_counter == 10, {25*10 = 250mS}, change the state of the Red LED and reset red_counter to 0. In Update_Blue(), make the Blue LED state equal to the button state. easy peasy.

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

    nicely presented.

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

    Thank you.

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

    I looooove the way you explain

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

      I have fun doing these and learn something new every time!

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

    Pretty good explanation of ISR, thanks.
    Maybe the pin names should be constants not variables. They are not going to change.
    const int BLUE_LED = 11;
    LOW and HI are constants also hence uppercase.

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

      "LOW and HI are constants also hence uppercase."
      Kinda,... not... they are defines.

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

    Great video !!

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

    Excellent indeed! I've suffered while you hot swap the connections.😅

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

    Very Well Done Video

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

    You are a wonderful teacher of embedded systems.
    Your style is very nice otherwise it's a very dry subject

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

      I have fun doing these. Writing the code is like telling a story of what you want to see happen in order from beginning to end.

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

    I have multiple routines that are called from the main loop which are selected by a mode variable. The interrupt works to change that mode variable but it still has to return to the main loop in order to take the next action. I would love it to just break off from whatever it was doing and back to the main loop. At least the button push registers and can be depended on. I just have to wait for the current sub to finish. I could have each sub check for a change in mode and bail but that's messy because every routing would need the same treatment. If I want to do that I might as well have each routing check the button inside the loops.

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

    So pretty and smart.
    The video was excellent !!!!
    Thanks for doing it.

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

      Glad you liked it! Let me know if you'd like to see any other topics.

  • @peterkowald7092
    @peterkowald7092 5 วันที่ผ่านมา

    So you asked has anyone ever written a multitasking function without using interrupts, and the answer is yes. I developed a cooperative multitasking core for any microcontroller after has a system that was doing a ton of work and struggling to get all done within a second. It took me a good while thinking about the problem before I developed the engine (it’s very very light weight and consumes only a few hundred bytes of memory. That same system doing all the same things (and now more) runs at around 15,500 cycles a second.
    I have now been using it for several years and use it on very project as it eliminated more code than it uses. In fact I even use it on top of RTOS because make coding do easy. So yo answer your question .. Yes
    I use it commercially so I won’t release it, sadly but I have a significant competitive edge killing systems with bigger, faster and more expensive microcontrollers.
    Nice bright video for beginners

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

    Great content and thank you for posting. I’m just getting started with Arduino so your posts are very timely but I’m wondering why you declared buttonState variable inside of loop. I was taught to only declare variables once otherwise the processor wastes resources. I think your code would still work if you declared before the loop. Do you agree?😊

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

    Thank you! I didn't know TimerOne library and its ease use! I think i could use it on a 16 steps MIDI sequencer i have built! Can it be used in combination with hardware interruptions? I need two hardware interrupts to control the state os two buttons.

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

    I would recommend when using such things as == LOW reverse it so LOW ==
    as it prevents mistakes like single = getting missed as a “var = const” will compile yet “const = var” will fail and you will pickup on the missing =

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

    Thanks for such an informative session. This video really helped me to take out the fear of using Interrupts.
    However, I have a question:
    If the Timer 0 interrupt is used....I should NOT be using delay or millis functions......but if I am using Timer 1 or Timer 2 .....can I use delay and/or millis in the loop function?

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

    Wow, you are so much fun. I don't know how far I will get with this arduino stuff. I'm 52 and originally just wanted to build an led cube but somehow got off into this coding. It's very interesting but having a difficult time retaining what I learn. I don't get to spend as much time on it as I would like to. You did a very good job explaining in your video and I completely understand but, 3 days from now I'll be like "how did that lady do that?". Lol, maybe I'm getting in over my head.

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

      I'm 64....Not as on-point as I used to be. I've found just reading about it is not enough for me.... "doing it" keeps it fresh in my mind.

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

    Thanks for the video. May I know for button interrupt, what if the button is kept to be pressed, is there any way to disable the interrupt and warn the user to release the button, then re-install the interrupt again?

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

    Good video. I think your next video should be interrupts based on serial read messages, like if that button was on a touch screen.

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

    When you refer to a function like setup or loop or any user defined function just say its name, "setup", "loop", or whatever it is called. Do not include "void", "int", or whatever it's return type is. The return type is part of the function declaration but is not part of the name.
    Good presentation. Nice to see someone that is obviously enthused about the topic.

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

      saying "void setup" adds clarity because the () are not spoken. IMO saying the return type is like prepending an honorific... like, "King Charles" instead of just "Charles."

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

    Great explanation, how about serial receive interrupts?

  • @user-cg7vx7pt1p
    @user-cg7vx7pt1p 3 หลายเดือนก่อน

    Linda e inteligente!
    Meu sonho de consumo!

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

    Your video is amazingly clear. thanks for the effort Rachel. Timers works in UNO but not in ESP boards. can you please suggest some library like the same that workks with esp32 boards?

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

    i am not a native english speaker.. i kind of have a hard time understanding various dialects..so, dear mam..THANK YOU!!! Its literally the first video I can understand 😭
    I am missing out a lot in school due to mental health reasons and I try to relearn all the stuff so i wont fall behind

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

    You are awesome

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

    I JUST FOUND YOU TODAY AND LOVED YOUR VIDEO. LEARNING CAN BE BORING, BUT NOT IN YOUR VIDEOS. I'M REQUESTING MORE CODING VIDEOS, YOU HAVE TWO, AND I SEE YOU PLAY THE VIOLIN , I HAVE ONE I HAVEN'T LEARNED TO PLAY YET. JUST A COUPLE OF SUGGESTIONS, THANK YOU WILLIAM

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

      Thanks so much for the suggestions! Yep - I have more coding videos coming - mostly Arduino and coding for robots/animatronics projects. I hope you pick up the violin soon!

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

      No need to shout.

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

    13:00 Regarding where to put additional functions in code, it's true that for the Arduino IDE+Compiler top or bottom is fine.
    However, if you're using an ESP32+Arduino Framework+PlatformIO+VScode I've found that (probably) the compiler complains about "undeclared functions" if you put them at the end, i.e. you try to call on a named function before it's seen in the code.
    There might be an additional parameter or something that can be parsed to the compiler, but that beyond me.

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

    Just a small comment @16:14. In this case, you only use 'buttonState' within the ISR, so it could be left local to that and wouldn't need the keyword 'volitile'. The only time this variable is changing is the line with 'digitalRead(buttonPin)' and that's only called in the ISR.
    An example where you would want it declared outside the ISR and WITH the keyword 'volitile' would be if it's changed inside the ISR (via that call to 'digitalRead(buttonPin)') and then used OUTSIDE of the ISR, (perhaps in 'loop()'). The compiler has no way of 'knowing' when the ISR may be triggered to change 'buttonState' so in loop() it must check the value in memory each and every time.

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

    This is really excellent. I have recently decided to do something with the Uno I bought mumblety years ago, and the billion others (also Nanos, Pro Micros, Megas and more) that I've hoarded over the last month. My electronics knowledge is rudimentary at best and, though I started my IT career 40*mumblety years ago as a programmer, I was never much good at coding. That's why I moved towards support, networking and my beloved UNIX. It's time for me to get back into writing crap code again and this is the sort of video I need to help me do that.
    Now all I need to do is find out how to make my Arduinos speak COMAL or Pascal. No? No :( bah.

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

    Thanks for this! With regard to the digitalPinToInterrupt, I wasn't sure if still need to use the proprietary pin designated by the board I have with this function? I.e. if the board I have has interrupt vector 0 on pin 2, can I use pin 10 and put digitalPinToInterrupt(10)?

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

      digitalPinToInterrupt will return an error (-1) if called with a pin which doesn't support hardware interrupts. Unfortunately attachInterrupt will silently fail to attach your function, and nothing will work. So no, you cannot use digitalPinToInterrupt(10).
      Cheers,
      Norm. (Author of Arduino Interrupts, published by Apress)

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

    Question: Is the interrupt routine being called twice each press since you used "change"? The pin is pulled up, then you press the button so it goes low and the interrupt gets called. When you release the button, is that also another change to high so it gets called again?

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

    In the hardware interrupt example, the buttonState doesn't need to be global and doesn't need to be declared as volatile because the first thing the interrupt handler does is to assign it to the return value of digitalRead() and the variable is not accessed anywhere else in the program.

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

    Multitasking without interrupts can be achieved using a system tick and tasks that you call after a sustained number of system ticks.

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

    Great video explanation was such that an idiot can understand. can you explain as I am using millis in one of project where I am using attiny84, and I want to make the current millis zero which I am not able do. also if I can use the interrupt for the same.

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

    Hi, Good Afternoon I am New to arduino and I am trying to put a sketch together by using a servo at 0 to 60 and use a IR sensor to activate it and also use a sound file or DF-Mini player for sound.
    Could you please help me with it ?

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

    I've used millis functions to multitask up to now. What would be the faster way? I'm working on an IR sensor changing state every 0,007 seconds, I need to be fast...

  • @jackkylejr.1112
    @jackkylejr.1112 4 หลายเดือนก่อน

    I have two water level switches on a aquaculture food system. The top switch tells when the thank is full and the water pump should turn off. And the bottom switch tells when the tank is empty and the pump should turn on. But I don't know how to code for to hardware switches that are in concert with each other???? Can arduino do this??

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

    doing the digitalRead for the digitalWrite to toggle the state - yeah that works but... ok, fine.
    Just having a state-variable would be nice, or use the already existing state: the arduino already has to know what state the PIN is in cause that is used directly by the hardware. And you can also read that state directly.
    For these simple tutorials the cost of a single digitalRead is not much and can be ignored, but if you had say 10 LEDs and wanted to blink them to get a dimming-effect than the delay quickly adds up (I think it was 4us for a read - with 10 LEDs that would addup to 80us/cycle - wich ends up in the audio-range. So if anything else is connected that has some mechanical movement this would not be good.)

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

    I have not long understood about using Millis instead of delay
    I have a question to ask
    If I have power to the Arduino
    And have a code programed installed
    Can I use a button to activate the code
    Meaning the code is dormant untill I press a button
    What I'm doing at the moment is have two LEDs blink via the Millis timing
    But it runs all the time so I have a button that is used as a circuit breaker and so when I press it it makes the leds connect
    But I would like to understand is there a way how to use a button to run the code to activate the LEDs only when the button is pressed

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

    Thanks for this ,can you do a video on Arduino Switch Case statements ,thank you Barros.

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

      Definitely! I had more requests for that same topic so I'll put it in rotation.

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

    I'm using I guess timer0. I maintain a sorted array of millis. If it's past that millis it executes changes else leave the loop. Drawback is it fails after 39 days or something like that.

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

    I did it with the LEDs flashing in binary with a string of code. I was attempting to create an effect similar as seen on Close Encounters of the Third Kind with Richard Dreyfuss . Most of you may not be familiar with the movie depending on your age. It was an attempt at communication with the Alien spaceship. I was not successful I could not recreate the sound frequency for each LED. as per the movie. I was having fun with LEDs, Relays, piezo speakers,

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

    Cool!

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

    I am wondering, can in this (interrupts) instance the blue led stay HIGH, while the red one keeps blinking (that is as with a latching switch or a longer delay on the blue led)?
    In my specific case, I am thinking of a simple buzzer piano for my nephew. Overingeneering as usual, I got this idea of having a song or predefined beats playing from one buzzer, while being able to play tones on the other buzzer by pressing keys. Already binge-researching and I certainly will need to do some partia demos to try the concept first, but if anyone has an idea to save me some dead ends...
    OMG, on additional hough, I may actually replace the key buttons qwith piezo touch sensors and possibly add a small amp (which have a couple of) to add an audio jack output. I really need to define an MVP to start with. :D

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

    Very good. Great explanations. But this is different from any use of the term "software interrupt" I've ever seen. Normally that refers to a processor instruction that invokes the same state save protocol as a hardware interrupt a la the x86 INT instruction. It's e.g. used to invoke OS functions. Timer interrupts are hardware. It's just that the hardware is on-board rather than external.

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

    Belleza, princesa