To learn how to use the Infrared(IR) receiver and IR transmitter.
To learn use the OLED.
- 1 x Micro:bit
- 1 x Breakout Board
- 1 x IR Receiver
- 1 x IR transmitter
- 1 x OLED
Put the micro:bit into the Breakout Board and put the OLED onto any of the 4 holes seen at the bottom of the Breakout Board.
1x Breakout Board
Pin the wires of the IR Receiver onto Pin 0(P0). Do ensure that it has been properly kept, or you will face problems later on.
1x IR receiver
1x Breakout Board
Good job! You finished setting it up! Before we get into actual coding... you have to download an extension. Go to the micro:bit website and create a new project. Scroll down and press ‘Advanced’ and look for ‘Extensions’. Click on it and search ‘tinker’. Download the extension showed in the picture.
Now let’s start coding! Ignore the first 2 lines. Make 3 new variables named ‘avg’, ‘time1’ and ‘count’. Initialise them by setting them to 0. Go to ‘Pins’, look for the block ‘set pull pin P0 to up’ and place it below the variables. This is to tell the micro:bit that there is an IR Receiver. Lastly, initialise the OLED and show the instructions of how this device works.
In the same ‘on start’ block, write this code. This serves as a simple countdown before the game begins.
In a new ‘forever’ block, write these code down. Make a new variable named ‘ir’. This will read the readings by IR Receiver. The pauses are to ensure the symbol(in this case, exclamation mark) appears randomly. The loop(green block) is to start counting the time until signal has been received by the IR Transmitter(Remote).
And you are done! You can now see how fast you are. To see the average on the OLED screen, you can press A and B. Remember to press the IR transmitter directly in front of the IR receiver. Enjoy!