140 likes | 197 Views
Radio communication between two micro:bits. It is possible to send messages between two micro:bits. This opens a range of possibilities, one of which being making one micro:bit control the other.
E N D
It is possible to send messages between two micro:bits. This opens a range of possibilities, one of which being making one micro:bit control the other.
This tutorial will walk you through setting up one micro:bit to control the other in a Kitronik buggy.
Controls • Using the accelerometer will allow you to tilt your controller micro:bit forwards and backwards to make the buggy drive forwards and reverse, and use the buttons to turn the buggy.
Language • The language used will be one called PXT IO. • This is a block version of JavaScript made by Microsoft, available at https://www.pxt.io/
How to communicate in PXT • PXT has a category called Radio. • Docs can be found at https://m.pxt.io/--docs#doc:reference/radio
How to communicate in PXT • The first step is to make sure that both micro:bits are in the same group. Both .hex files must start with this block and use the same number between 0-255
How to communicate in PXT • The sender can now send numbers to the receiver
Message Sender • I send one of three numbers: • 10000 for left • 20000 for right • The value of the accelerometer (In the Z Axis) for forwards/ backwards/ stop
Message Receiver • The logic to drive the buggy happens in the receiver. • I set a variable called “number” to the number received over radio and then use nested ifs to act depending what number it is.
Message Receiver • If the number is between -100 and 100 i.e. the micro:bit is relatively vertical all pins will turn off (stop buggy)