Can MicroBlocks support interrupts?

Issue #319 resolved
梁帅 created an issue

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)

  1. John Maloney repo owner

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

    scriptImage815251.png

    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!

  2. 梁帅 reporter

    Amazing!!!! It works! 🎉🎉 And the task function is quite easy to use!

    Thank you vary much!

  3. Log in to comment