ラベル dice の投稿を表示しています。 すべての投稿を表示
ラベル dice の投稿を表示しています。 すべての投稿を表示

2018年5月20日日曜日

Making custom blocks(with JavaScript) for micro:bit applications

This small article describes a feature of micro:bit visual block (with JavaScript). In particular, it is about user's block definition function. In the last article (No. 3), micro:bit was used as an indicator of pips of the dice. Dice is also commonly used in games and other applications.

Therefore it is convenient to have a custom block (user defined block) to display the dice 's eyes on the LED. To exceed the beginner level, it is essential to use this custom block function. A simple example is shown below. 


In the following, the function "show_pips_on_dice" was defined as a custom block. The argument denotes the number of pips of the dice. Every time you press button A, the eyes of the dice are displayed in ascending order. Thanks to the custom block, you can write it concisely like this.

Using custom block for displaying pips on a dice

The setting of this custom block is performed as shown below. Define this function "show_pips_on_dice (n: number)" in the namespace "custom". Then you can use (call) this function as a block from the menu "Custom". This definition content is stored in a file called "custom.ts".

Definition of a custom block for displaying pips on a dice


2018年5月14日月曜日

Cooperation between micro:bit and MIT App Inventor (No.3)

In the last article (No.2), communication between micro:bit and Android smartphone was done with Bluetooth UART service (serial over Bluetooth). I will also use this UART this time, but I would like to consider a simple example including NFC which is a short range wireless communication other than Bluetooth.

The figure below shows the contents. Prepared here a big toy dice. We prepared six NFC tags on which the number of eyes on each side are written, and incorporated them on each surface of the dice. Flip over the Android terminal and touch the dice on the back of it. Then the number of eyes on the opposite side of the touched surface is read. The number of eyes read is sent to micro:bit by UART communication. Pressing the micro:bit buttonA will make it receive that information and display the number of eyes on the micro:bit LED.



please see also the following youtube:
https://youtu.be/aOb69nweq3c

Using NFC in addition to BLE UART

The Android program was created using MIT App Inventor. After reading NFC tag information (number of eyes of dice), it will send the number of eyes on the opposite side of that face to micro:bit using UART. At the same time, an image corresponding to the number of eyes should be displayed on Android's screen.

Android program (reading NFC tags and sending with UART)

On the micro:bit side, pressing buttonA gets the number of eyes sent from Android, so we just display it on the LED. The function "show_spots_on_dice" is defined with JavaSript as a custom block. In this example, since we received 4 as the number of eyes, the four outer corners of the LED are lit.


micro:bit program to receive the pips of a dice and to display it on the LED board