This is the best channel on TH-cam for Arduino tutorials! You have a knack for teaching this. Idea for a future video(?): I'm trying to integrate a TM1637 into my project. While the project is idle, the TM1637 displays a static number. After a button command is given, a motor runs and while the motor is running I'd like the TM1637 to illuminate one segment and make the segment crawl around the display like an hourglass timer. When the motor stops, a static number would again be displayed. I've written the routine that makes the segment crawl around but I'm using delays to accomplish this and of course that delays the rest of the code.
Great video and explanation! Two questions if I might. 1. Can you use delay function inside the ISR? 2. Can I have an internal loop inside an ISR so as to do 3 parallel things? (one on main loop and 2 parallel jobs and checks on pins 2 and 3). Finally, can I "share" variables between main loop and ISR functions (volatile maybe or something?). Thanks a lot for the great video.
Thank you for the kind words, 1) no, they are not working. The ISR needs to be quick, so the best thing to do in an ISR is to change a variable and leave the ISR. 2) unfortunately no. Arduino does not support multitasking. You can only execute one loop at a time. The best thing that comes very close to multitasking is to write non-blocking code. take a look at my video 15 about millis: th-cam.com/video/FIYjw0AhTkA/w-d-xo.htmlsi=ZCbUe6wDghEty-Xc 3) yes! it works great with global volatile variables you need to add volatile otherwise you could run into some troubles. You need to define them outside of setup() and loop() usually at the very top of the sketch.
Very nice video. Well explained and perfekt view on source and hardware. Just very minor possible improvement: At the end you didn't demonstrated on the hardware, that the other player can't win anymore, since you detached the interrupt.
can an interrupt interrupt another interrupt? for example, could the buttons be pressed at the precise time that the other interrupt is triggered to run after one of the lights turn on but before the interrupts are unregistered?
During an interrupt, further interrupts are disabled. You can, if you know what you are doing, enable interrupts in an ISR but it's not recommended. Cheers, Norm. (Author: Arduino Interrupts published by Apress)
very good question, as @NormanNodDunbar already pointed out, inside the ISR, interrupts are disabled by default. if you really need it, you can call the function interrupts() inside of the ISR to enable them, you can also disable them again by calling noInterrupts()
maybe you can explain your concerns in more detail. of course everything breaks at a certain emc noise level. Adding some capacitors in parallel to the switch would help you in this type of environments.
This is the best channel on TH-cam for Arduino tutorials! You have a knack for teaching this.
Idea for a future video(?): I'm trying to integrate a TM1637 into my project. While the project is idle, the TM1637 displays a static number. After a button command is given, a motor runs and while the motor is running I'd like the TM1637 to illuminate one segment and make the segment crawl around the display like an hourglass timer. When the motor stops, a static number would again be displayed. I've written the routine that makes the segment crawl around but I'm using delays to accomplish this and of course that delays the rest of the code.
Thank you! This sounds like a great application for a timer library or millis() ;)
@@playduino Thanks! I'll check out your millis video 🙂
Very detailed and thorough. Were wondering if any of our custom service like PCBs would be helpful in your future projects. Can anyway reach you out?
Great video and explanation! Two questions if I might. 1. Can you use delay function inside the ISR? 2. Can I have an internal loop inside an ISR so as to do 3 parallel things? (one on main loop and 2 parallel jobs and checks on pins 2 and 3). Finally, can I "share" variables between main loop and ISR functions (volatile maybe or something?). Thanks a lot for the great video.
Thank you for the kind words, 1) no, they are not working. The ISR needs to be quick, so the best thing to do in an ISR is to change a variable and leave the ISR.
2) unfortunately no. Arduino does not support multitasking. You can only execute one loop at a time.
The best thing that comes very close to multitasking is to write non-blocking code.
take a look at my video 15 about millis: th-cam.com/video/FIYjw0AhTkA/w-d-xo.htmlsi=ZCbUe6wDghEty-Xc
3) yes! it works great with global volatile variables you need to add volatile otherwise you could run into some troubles. You need to define them outside of setup() and loop() usually at the very top of the sketch.
@@playduino Thank you very much for your prompt reply! I will watch your video right away. Thanks again!
Very nice video. Well explained and perfekt view on source and hardware. Just very minor possible improvement: At the end you didn't demonstrated on the hardware, that the other player can't win anymore, since you detached the interrupt.
Thank you for the nice feedback :) I agree, however both LEDs would have turned on after my test with two fingers
Hello, Does the rule regarding the UNO and pins 2 and 3 for the Interrupt function apply to the MEGA 2560 R3 board?
Hey! Arduino MEGA 2560 has more external interrupts:
this pins can be used: 2, 3, 18, 19, 20, 21
can an interrupt interrupt another interrupt? for example, could the buttons be pressed at the precise time that the other interrupt is triggered to run after one of the lights turn on but before the interrupts are unregistered?
During an interrupt, further interrupts are disabled. You can, if you know what you are doing, enable interrupts in an ISR but it's not recommended.
Cheers,
Norm. (Author: Arduino Interrupts published by Apress)
very good question, as @NormanNodDunbar already pointed out, inside the ISR, interrupts are disabled by default.
if you really need it, you can call the function interrupts() inside of the ISR to enable them, you can also disable them again by calling noInterrupts()
But using this with noisy enviroment, it becomes a problem and impossible to use
maybe you can explain your concerns in more detail. of course everything breaks at a certain emc noise level. Adding some capacitors in parallel to the switch would help you in this type of environments.
@@playduino yes, i've no choice. Using a hardware solution is more abvious in this case. Thanks for your help
Red finger is faster? I think its was green
Omg 😆 yes