15. Case 14: Guess the tones

15.1. Introduction

Make a micro:bit device that is able to recognize the tones.

../../_images/case_14_01.png

15.2. Quick to Start


Materials


Nezha expansion board × 1

micro:bit × 1

Connection Diagram


  • Connect the micro:bit to Nezha expansion board as the picture shows.

../../_images/case_14_03.png

15.3. MakeCode Programming


Step 1


Program to show icon in the on start brick and set the variable K as 0.

../../_images/case_14_11.png

In forever brick, set the variable j as true and the value of i as a random number among 1~7.

../../_images/case_14_12.png

If i=1, programme to play the tone of C; if i=2, set to play the tone of D, and set the following 5 tones accordingly in the same way.

../../_images/case_14_13.png

While the variable j is true, set k=k+1 after button A being pressed and display the value of K; while button B being pressed, if k=1, set to display √; if k≠i, set to display ×, and pause for 2000ms, then display the smile face; if k=0, set the variable of j as false.

../../_images/case_14_14.png

Full Code:

../../_images/case_14_15.png