Sending an Indication to Another Circuit Playground Express

In MakeCode, the infrared communications blocks are in the NETWORK block group.

You can send a number of your choice over infrared with the infrared send number block. On the receive side, a trigger block, on infrared receive runs code blocks when the board detects an infrared signal. The variable num has the numeric value received.

You can compare the numbers sent and received to determine if that is the signal you were looking for or not. With a simple one-on-one conversation, the number can be anything. In a whole classroom of Circuit Playground Express boards, you may only want to trigger when you get a special number received by the instructor or your friend.

An Example

The example below has the Circuit Playground Express lights all set to green in the forever loop. 

If button A is pressed, the number 9 (an arbitrary number) is sent via IR.

If a Circuit Playground Express receives any number, it will run two blocks: set all pixels to red and wait for 1,000,000 microseconds (1 second). 

Normally the lights would immediately turn green again due to the forever loop. But the wait doesn't let that happen (it blocks other code from running until it finishes waiting) so you will see the red lights indicating a detection for the wait period. Then the NeoPixels will turn back green. Another receive starts the red display for an additional second.

Load the code below on two or more Circuit Playground Expresses.

Using This Code

Download the same MakeCode to two or more Circuit Playground Express boards. They should indicate all green when they don't detect anything.

Aim the two boards at each other. Start off at about 4 inches / 10 centimeters away from each other.

Press the A pushbutton on one board. If the send and receive are roughly aligned on each board, the LEDs on the receiving board will turn red for 1 second then turn green again. Press the A button on the second Express and the first boards' LEDs should turn red.

This can be used a number of ways. Games, sending sensor values, etc. A fun project is Circuit Playground Express Laser Tag.

This guide was first published on Jul 26, 2018. It was last updated on May 27, 2024.

This page (MakeCode) was last updated on Mar 08, 2024.

Text editor powered by tinymce.