In the last post I mentioned that the boys also wanted to try programming Minecraft mods. We did try one lesson, but it was a bit of a learning curve for all of us, just working out how to connect to and run the development environment in the browser. I think I need to go away and run through it in advance otherwise progress is too slow and everyone gets frustrated.
So I decided to carry on with the micro:bit.
Send a Message
The first project was simply to get the micro:bits to send messages to each other. I showed them how to set up a program to show a received radio text message and then send a text message.
They then coded the buttons to send three message (A, B and A+B).
That was quite fun to press the button and see the message appear on the other micro:bit.
Here's the code my eldest, Anton wrote:
Hide and Seek
So - we had established that the micro:bits could talk to each other. Now I wanted to establish how the signal strength could be used to determine how close to each other the micro:bits are.
We could then use this to play a game of hide and seek, where one person hides the micro:bit, and the other has to try and find it by looking at the signal strength.
So the idea is each micro:bit would broadcast a text message every few seconds. They would also receive messages and output the signal strength.
I explained how the signal strength ranged between -128 (weakest) and -42 (strongest).
I also showed them the built in mapping function to map between 2 different ranges. This is a really useful function as it's something that you need to do quite often, but is not straightforward (especially for a 6 year old). So being able to map this in a single function is great.
We originally used the 'plot bar graph' function to show the signal strength and then tried hiding the micro:bit. This worked OK, but the signal strength tended to stay the same until you got really near to the other micro:bit.
So we decided to use a larger range (0 - 99) and show the number on the micro:bit screen instead. Here's the code we wrote:
The blanking of the leds when the message is received is a hangover from when we displayed the bar graph and wanted to see that it actually changed. It's not necessary when displaying a number.
This worked slightly better - although the value was varying quite a lot as you moved around. It was only when you got really close to the other micro:bit than the value started increasing over about 30-40.
But - it did work. They were able to find the micro:bits and had a lot of fun playing with them after they had done the coding.
I wonder if changing the signal power to something weaker than 7 would have helped? Also - it might be worth going back to the plot bar graph method - which was a nicer display, but ignore weaker signals. We may be able to revisit this in the next lesson.
Next Time
For the next lesson we'll go with the chuck a duck project. This is a game the whole family will be able to play where one micro:bit starts with a 'duck' icon on the screen. The player with the duck has to shake the micro:bit to send it to another random micro:bit. We'll put in a timer so that the player with the duck when the timer runs out loses. So far the projects have been pretty simple, so we've been coding as we go. For the chuck a duck project, I may need to try this out in advance, just in case there's any little issues we come across that might be frustrating to solve when playing the game.
No comments:
Post a Comment