My kids like easy coding with Scratch or mBlock. I found a nice Arduino shield for them to play with, only it could only be programmed with the Arduino IDE. Luckily mBlock provided a way to extent the mBlock environment.
The Arduino Multi Function Shield is a low cost shield provided by several suppliers.
It contains a lot of basic IO for fun experiments. Typical the stuff you put normally first on a breadboard.The shield contains:
- 3x push switches
- 4x leds
- 1x buzzer
- 1x potentiometer
- 1x 4 segments 3461 BS display
- And some interfaces for optional io/sensors
You can code it your self in the Arduino IDE or use an existing library like the arduino-multi-function-shield library
mBlock is a Scratch like IDE for making computer program, but it also supports several hardware platforms like the mBot, but also Arduino. My kids use this very accessible environment for the mBot, but is also support other hardware like the Arduino Uno.
To make the it able to use the Arduino shield in mBlock, a so called extension should be created for it in the mBlock online extension builder.
When a extension is finished it can be published for approval. In the will so up in the Extension store.
In the extension center you create for a certain category a number of blocks.
Each block can be hooked to matching C code for :
For use it needs to be added to you mBlock environment. Unless you want to hack the extension yourself, you can use the MF Shield from the extension center.
Below are the new blocks created for use with the MF Shield and are available in mBlock:
The MFS library use a Timer in the background to update the leds, display segments and read the switches.The MFS library has a very nice way to read the switches; it puts every event in a round robin queue.The function MFS.getButton get the first one from the queue. Using this function several times in the main loop is a bad idea.
That’s why the functionality is splitted in two;
- get first entry in the queue – (get button state block)
- eval if a certain key is pressed – (is button [x] [pressed] in [button state] block)
Read the switches
If you only have one button test you can use the get button state block directly in the eval block. If you have multiple you first need to store the button state into a variable and use that variable in the eval:
Only one switch test in your program:
Use multiple switches in your program:
Try out the extension before it is published (before is applied to and approved by the mBlock Des):
- Click in the extension editor download
- Save it own disk
- Open mBlock
- Open an explorer to the downloaded extension
- Drag and drop it onto mBlock
- Restart mBlock
- Chose add extension
- Add the MFS extension to your project (project device has to be an Arduino, only tested with the Uno)
If you to update the extension repeat step 1-6.
You can find the extension on:
- Also published it with the mBlock extension center
Other handy links:
- mBlock documentation
- mBlock forum
- https://www.cohesivecomputing.co.uk/hackatronics/arduino-multi-function-shield/ C library for use with Arduino IDE
If display segments are used with raw data (instead of display test use set display segment) you can enable each led of the segment. A-DP are the bits of the segment.