Open KidsBlock and connect the board to your computer. Click File –> Load from your computer.
Choose D:\Code\1.Code_kidsuno to open 4.7Air pressure detection.sb3 file.
Click to connect to port and then .
Conceive:
Generally, air pressure within 950hPa ~ 1050hPa is regared as the normal range. If the pressure is lower than 950hPa or higher than 1050hPa, human may have a headache or dizziness, and even some meteorological disasters will happen.
Set 950 and 1050 as two thresholds to divide the pressure into three ranges.
low pressure: lower than 950hPa
normal pressure: 950hPa ~ 1050hPa
high pressure: higher than 1050hPa
LED will light up in corresponding colors when the pressure value is in the related set range.
Within low pressure range: the yellow LED lights up.
Within normal pressure range: the green LED lights up.
Within high pressure range: the red LED lights up.
Code structure:
Initialization. set the pins of LPS331APTR air pressure sensor and the traffic light module.
Loop.
LPS331APTR sensor reads the air pressure value and outputs it.
Determine which range of the pressure value is in, in order to turn of related LED.
air pressure > 1050hPa: the red LED lights up and other two LEDs goes off.
air pressure < 950hPa: the yellow LED lights up and other two LEDs goes off.
950hPa < air pressure < 1050hPa: the green LED lights up and other two LEDs goes off.