3.36 wifi Piano

3.36.1 Overview

In this project, we set seven buttons to control the speaker to play tones of Do, Re, Mi, Fa, So, La, Si.

3.36.2 Test Code

You can manually build blocks, or directly open the code file we provide: 3-36-Web Piano Panel.ubp. If you have any questions about how to open code files or upload code, please back to 1.9 Upload Code.

Build code blocks:

  1. In , drag to the script area.

  2. Drag t195 and set the WIFI name to “LiuTest” and password to “88888888”.

  3. Drag t196 and set the Web name to “CodingBox.local”.

  4. Add t170 to refresh the data of each sensor on the Web page.

  5. Use t198 and set the title to “Coding Box Web Piano”.

  6. Use t207 to add a button that controls the speaker and set the label to “Do”.

  7. In tone, drag img to “copy callable name”, and paste it to the blank behind the “with selector” of the t221. Click t219 to add a “params” blank.

  8. In , drag t217 and click t219 to add one more blank. Put it into the “params” blank of thet222, and modify “cat” to “100”, “dog” to “300”.

t223

  1. Similarly, set tones of Re, Mi, Fa, Sol, La, Si.

Complete code:

t224

3.36.3 Test Result

Connect the coding box to the MicroBlocks via USB or Bluetooth. Click t59 to upload code. After connecting to wifi, you can see an IP address: t212. Now connect your control device (mobile phone, tablet, computer) to the same wifi and search codingbox.local on the browser to enter the Web page.

Click the corresponding button on the Web page, the speaker will play the related tone.

t225