Welcome to the DFRobot blog
:
www.dfrobot.com/blog-tag-microbit.html
39
/
86
Goal: When the analog value of sound sensor is less than 50, the on-board LED displays a number
"1", indicating that the volume is low; when it is greater than 50, the on-board LED displays a
number "2", indicating that the volume is high.
STEP 1: We will put the LED module aside for a moment and focus on the logic part. Function “if
else” and operator “=” will be applied in this part. Both of them should be placed into “forever”
loop. The “if else” function can be used to judge which number should be displayed. Which means
that if the logic statement on the right side is met, the code sentence to the right of "then" should
be executed, whereas the sentence to the right of "else" should be executed if the logic statement
is not met.
STEP 2: The sound sensor is connected to P0, which means we will use the “analog read” function
to get the readout on P0. As explained before, the analog signal ranges from 0 to 1023.