Tuesday 13 September 2016

How Big Can My Python Script Be?

We all know that the micro:bit has limits. The specs (available either on WikiPedia or the ARMmbed site) show that the memory limits are:
  • 16kB RAM
  • 256kB Flash 
That sounds like a decent amount of memory - it's not in the gigabytes range of even your most modest modern PC or Mac, but for an embedded processor a total of 282kB is not too bad. So surely we can load massive Python scripts onto our micro:bits, right? Wrong. The hard limit for a Python script is just a snip under 8k. Try and copy a script file larger than that and it will fail. Why is that?


Tuesday 6 September 2016

What are .hex files?

You must have come across .hex files by now. Every time you compile a program on the micro:bit website you end up with one. You copy it to your device and the program runs. Every time we post a project on this blog we include a .hex file. Every time you hit the Flash button in Mu it silently and secretly creates a hex files and automatically copies it to your micro:bit. But what are .hex files, how do they work and why should we care about them?

Thursday 1 September 2016

Tilt Maze

Son and I recently went off for a boy's weekend at the Grandparents. We knew that we'd be stuck on trains for a good few hours so we decided to take along the micro:bit so that we could embark upon our own Train Jam. Son chose to work on a maze game where you have to navigate your way to the exit. He also wanted keys and doors to make it more of a challenge.


We thought it might be tough to make this a fun game on such a limited device so we decided to keep things simple. With only 25 red LEDs it was tough to think how we could show the various elements of the maze. We decided that:
  1. The player would be a very bright pixel and always in the middle of the screen. The rest of the maze would scroll around you.
  2. Walls would be dim pixels.
  3. Doors would be slowly flashing pixels.
  4. Keys would be rapidly flashing pixels.
  5. The exit would be flashing in some cool way that made it look enticing.

Tuesday 16 August 2016

Micro Alarm

This is our first hardware project - an alarm. It's (very) inspired by Tech Will Save Us' Micro Guardian. The project is pretty simple, but it's a fun one to make. We set up the micro:bit with a connection between pins 0 and 3v using crocodile clips attached to two strips of copper tape. The copper tape goes across the seal of a jar, making a connection when it's closed and breaking it when it's open. We detect this in the code and, when the connection is broken, we output a pulse to pin 1 which has a buzzer connected to it (the other connection of the buzzer goes to GND). We also used some of MicroPython's built-in images to show the micro:bit asleep face when the connection is closed, and alternating between angry face and sword (Son was insistent that the micro:bit show you that it is both angry and ready to fight you) when open.


Monday 8 August 2016

Snake

Here's our second game, a version of the classic snake game. A bit of a challenge to fit this onto a 5x5 display with only two buttons but we think we've managed it. Drive the snake around the screen using the A and B buttons to turn left and right. The aim is to eat the food (the flashing pixel) but your snake gets longer each time it eats something. Eventually your snake tail will be so long that you'll crash into it and it's game over!


Friday 5 August 2016

Non-Flappy Bird

Here we present our first micro:bit game - Non-Flappy Bird. We wanted to write a version of Flappy Bird, but on a 5x5 display there didn't feel like there was enough room for flapping. So instead of flapping, we made the A and B buttons move you left and right. Rows of lit pixels drop down the screen towards you and you'll need to dodge them. The game gets faster the more barriers you avoid.


Thursday 4 August 2016

Custom Display Clear

MicroPython has a simple built-in command to clear the display: display.clear(). The results are equally simple - it instantly turns off every LED on the display. We don't need to be limited to such a simplistic way of clearing the screen though, we can write our own exciting fades, wipes and dissolves.