Posts

Building an extension for MakeCode for micro:bits

Image
  I have built a couple of extensions for MakeCode, but it was not without pain. The trouble is that the writers of the documentation, such as Building your own extension , don't know my limitations (I'm not a professional coder, for one). So I'll try and show you one way to do the job - there are other ways which may suit someone who is familiar with Node.js and so on, but I'm more at home using a browser. A browser and a text editor are all you will need! I'll use my Bitwise Logic extension as an example. The functions operate on each bit of a number and are very useful when we are interfacing a micro:bit to other electronic devices. The first thing to do is to work out which blocks you want to create. I'll start with a really simple block - it provides the bitwise NOT function . In JavaScript that is represented by the ~ operator. So to invert each bits of the variable called a you would write: ~a In our blocks view of the world we want  to make a block li...

Real Time Clock

Image
 Here are a few reasons why you might want "real" time on a microbit: if you are recording measurements ( data logging) you probably want to record the time you made them - this is known as a timestamp . if you are automating something, such as a security light, you might need to do things at a particular time. The microbit can measure elapsed time, which can be useful, but you need to know the date and time when you started the timer. You can use the data logging feature in MakeCode but that (at the moment) doesn't make a timestamp, and your microbit would have to be connected to a computer running MakeCode. I want to run data logging without connecting to a computer, so that the microbit is a self-contained module. So adding a small Real Time Clock module solves the problem. I can upload measurements, with their timestamps, from the microbit, once a day or once a week, for example. This project uses the Tiny RTC module which is really small (23 x 27 mm)! It includes a...