To start with I wanted them to see how the accelerometer behaved as the micro:bit was moved around, so we output the values to the serial port and started up the console monitor. (The example below shows the simulator, but during the lesson, we were connected to the micro:bit and viewing the remote console.)
Code to write accelerometer values to serial port |
Output from serial port on console monitor |
We talked a little about what the values meant - and how they related to gravity. The z value was a constant -1023 because there was 1g acting downwards on the board.
As the micro:bit was tilted from left to right, the x values changed from -1023 to +1023 and the z value moved towards zero at the same time. Likewise, tilting it forward and backwards changed the y values, and again the z value changed.
I asked them what would happen if we turned it upside down - and Anton correctly guessed that the z value would go from -1023 to + 1023.
So now on to actually using the values.
This was only going to be a short lesson, so we decided to go for a quick program to move a dot around the LED screen.
So we wrote the following program together:
And this did the trick.
I was going to look at using the accelerometer, together with the radio signals to build a simple burglar alarm, but I've just ordered a couple of new Kitronic :MOVE Motor robots, so the lesson plan may change a little ....
No comments:
Post a Comment