Lesson 7 – Read Infrared Key Assignments
Tutorial –
Objective – As part of this tutorial we will learn howto read the keys pressed on an infrared remote control.
- With an understanding of the keys pressed on an infrared remote control you can use these remote control to get your robot to perform any given set of actions.
- As part of this tutorial we will send signals to the robot using the remote control (IR Transmitter), receive the signals on the robot (IR Receiver).
- We will then display the value of the remote control key that was pressed.
- To keep things simple we will only display (in decimal notation) the last two digits of the key that was pressed.
Setting things up – Let’s head over to the BBC MakeCode website (https://makecode.microbit.org) since we will be using the MakeCode block editor to code the Micro:Maqueen.
Before we can write any code and get our robot to do stuff for us we need to include some specific libraries (Code) that will allow the BBC Micro:Bit board to understand the different components, capabilities of the robot. We call this special code libraries.
Here’s the steps to import the library –
- Head over to the MakeCode website at : makecode.microbit.org using a new browser window. The first time it loads things might be a bit slow.
- Let’s create a new project to get started.
- Now go ahead and let’s import the library.
- Click the gear icon shown on the right hand side of your screen, click on “Extensions” and then enter the library address: https://github.com/jhlucky/maqueen
- Import the library by clicking on it.
Let’s Get Coding – Enter the code provided below into your MakeCode Editor where you have loaded the Micro:Maqueen libraries.
Upload the code to the micro:bit and you should be able to start reading values of the keys pressed on the remote control. So go ahead, press any of the keys on the remote control and watch the relevant key numbers (last two digits in decimals) displayed on the micro:bit.
The key assignments in the following table are in hexadecimal. As part of the tutorial, we read the last two digits of the key assignments and automatically converted them to decimal data.
Have a look at the sample program at – https://makecode.microbit.org/_361V7bbp0UAg
Prerequisites –
- This development track makes extensive use of the BBC micro:bit.
- If you haven’t purchased a BBC micro:bit yet you might want to head over to OzToyLib and pick one up now.
- We would recommend that you pick up the BBC micro:bit kit which comes with a battery pack, usb cable and the real micro:bit.
- We will be using the official online BBC MakeCode Block editor to write code for all our tutorials. No investment required here.
- You will also need a Micro:Maqueen STEM robot to be able to work on this development track. You can pick up the Micro:Maqueen robot from OzToyLib.
Reference –
- To learn more about the BBC micro:bit please visit – <Link>
- To learn more about global re-sellers of the BBC micro:bit please please visit – <Link>
- To learn more about Kitronik please visit – <Link>