# Infrared remote for multi-tasking

**URL:** <https://forum.makecode.com/t/infrared-remote-for-multi-tasking/4482>\
**Category:** micro:bit\
**Created:** [November 18, 2020, 9:26am UTC](https://forum.makecode.com/t/infrared-remote-for-multi-tasking/4482 "2020-11-18T09:26:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shirley](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@Shirley](https://forum.makecode.com/u/Shirley)\
**Post date:** [November 18, 2020, 9:26am UTC](https://forum.makecode.com/t/infrared-remote-for-multi-tasking/4482/1 "2020-11-18T09:26:46Z")

</div>

Hi, i’m trying to use an infrared remote to control my robot for doing different kind of tasks.

Just like by using button A/B for interrupt a loop. However, it doesn’t work. The coding only allow button A to interrupt the loop but not infrared button NUM1. Here’s my simple coding.

 ![2020-11-18](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/a/aa2e8e8473f0d5a4936d6c5aecff0eadfaf070fd.png)

Anyone can help to solve it? Many thanks!

---

<div class="post-metadata">

**Author:** ![MKleinSB](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/mkleinsb/32/593_2.png) [@MKleinSB](https://forum.makecode.com/u/MKleinSB)\
**Post date:** [November 18, 2020, 1:18pm UTC](https://forum.makecode.com/t/infrared-remote-for-multi-tasking/4482/2 "2020-11-18T13:18:32Z")

</div>

Put a “set a to true” in “on start” and test it.  
I think otherwise the variable is block-scoped which means in reality you have three different Variables named a and not one which is changed.

---

<div class="post-metadata">

**Author:** ![Shirley](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@Shirley](https://forum.makecode.com/u/Shirley)\
**Post date:** [November 19, 2020, 2:39am UTC](https://forum.makecode.com/t/infrared-remote-for-multi-tasking/4482/3 "2020-11-19T02:39:57Z")

</div>

Hi MK,

Thanks for your suggestion. However, it doesn’t work. In this simple coding example, the purpose is to show “small heart” when infrared remote control button “NUM1” is pressed, so as to testify the while loop has been interrupted by infrared remote control.

However, as said, it seems only button “A” in microbit can interrupt the while loop not the infrared remote control.

Is there any solution for that?

Many thanks!

---

<div class="post-metadata">

**Author:** ![joshkeys19](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/joshkeys19/32/2182_2.png) [@joshkeys19](https://forum.makecode.com/u/joshkeys19)\
**Post date:** [December 19, 2020, 4:41pm UTC](https://forum.makecode.com/t/infrared-remote-for-multi-tasking/4482/4 "2020-12-19T16:41:10Z")

</div>

Hi Shirley,

Try adding a basic.pause(100) in your while(a) loop. When using while loops, you run the risk of event based items not getting a chance to run. When put a pause in, it gives the scheduler a chance to run.

I also agree with the block-scoped variables. I’d delete all instances and start with a new variable name on start, then add to the others just to be safe.

What IR extension are you using?

Thanks,  
Josh

---

<div class="post-metadata">

**Author:** ![Shirley](https://avatars.discourse-cdn.com/v4/letter/s/c37758/32.png) [@Shirley](https://forum.makecode.com/u/Shirley)\
**Post date:** [December 22, 2020, 4:08pm UTC](https://forum.makecode.com/t/infrared-remote-for-multi-tasking/4482/5 "2020-12-22T16:08:01Z")

</div>

Hi Josh,

Thanks for your advice. However, your suggestion also doesn’t work. My IR extension is [https://github.com/iot789/microbit-makecode-IR.git](https://github.com/iot789/microbit-makecode-IR.git). You may try to see if you can solve this problem. Thank you so much.

Rdgs,  
Shirley

---

<div class="post-metadata">

**Author:** ![bsiever](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/bsiever/32/1032_2.png) [@bsiever](https://forum.makecode.com/u/bsiever)\
**Post date:** [December 23, 2020, 4:28pm UTC](https://forum.makecode.com/t/infrared-remote-for-multi-tasking/4482/6 "2020-12-23T16:28:56Z")

</div>

For this specific example I think you can just change where you set the icon and omit the loops and flag variable (`a`). For example, set it to the _large_ heart in `on num0 pressed` and set it to the _small_ heart in `on num1 pressed` (and `on button A pressed`).
