Can MicroBlocks support interrupts?
Issue #319
resolved
I’m developing a mobile robot product based on MicroBlocks programming environment. It is necessary to use infrared encoders to measure the speed of the motors, but at present, MicroBlocks does not seem to support interrupt operation.
I really hope that MicroBlocks can have such a function. Thanks!
Comments (4)
-
repo owner -
reporter Amazing!!!! It works! 🎉🎉 And the task function is quite easy to use!
Thank you vary much!
-
reporter
-
repo owner - changed status to resolved
- Log in to comment
I've started experimenting with encoder motors. They're fun!
You don't need interrupts to use encoder motors in MicroBlocks; you can just use a task to count encoder steps. Here's an example that turns a motor connected to a Wukong board for 336 encoder steps (one complete revolution for that particular motor):
You can also write a script that computes the motor speed from the time between encoder steps. The key using two wait until blocks to wait for a pulse (the encoder input pin going high and then low again).
Hope that helps!
P.S. The reason Arduino scripts use interrupts for things like this is because Arduino C++ does not support tasks (a.k.a. threads). Since MicroBlocks has tasks, this is easier to do in MicroBlocks!