Microbit Halo Programmable Expansion Board Tutorial 1.5 Sound test (download)
Microphone is connected to the P1 of micro:bit and detects the current sound size by reading the analog value of the micro:bit P1. The larger sound of the current environment, the larger the analog value read, the smaller sound of the current environment, and the smaller the analog value read.
2. Learning goals:
In this lesson we will learn how to realize that when the larger sound of the current environment, the longer the graphic bar on the dot matrix; the smaller sound of the current environment, the fewer the graphic bars on the dot matrix.
3. Programming method:
First, we need to connect the micro:bit to the computer by USB data cable, the computer will pop up a USB flash drive.Then, click on the URL in the USB flash drive: http://microbit.org/ to enter the edit process interface.
Open the offline programming software,download address of this software: http://www.microbitgo.com/code.
After creating a new project, you need to load the Neopixel library to program the programmable RGB lights. To load the library, click on 【Advanced】—【Extensions】 — click on 【Neopixel】, and you will see an extra column in the programming interface. As shown in the figure below.
General program diagram:
Our programmable RGB lamp is connected to the pin2 of micro:bit, so the pin2 is set to no pull-up/pull-down mode by default. Then use the following statement to create a new NeoPixel driver named Strip.
The initialize strip is set to black, meaning that the RGB light is turned off.
Then in the main loop, we need to use the draw graph bar statement to display the analog value of the read P1 as a graph bar on the dot matrix. The maximum value is 1023.
We need to make sure that the micro:bit board is connected to the computer. Click the download in the lower left corner as shown below, and select the download path as micro:bit drive letter to download the program.
After the program is successfully downloaded, you can see that fewer the graphic bars on the dot matrix. When we increase the sound or take a breath to microphone, the graphic bar will grow. As shown in the figure below.
- Last Tutorial>> Microbit Halo Programmable Expansion Board Tutorial 1.4 Breathing light
- Next Tutorial>> Microbit Halo Programmable Expansion Board Tutorial 2.1 marquee