Peripheral myB As BarometerA @ 0 ' Set the module ID as 0 Dim g_wP As Word ' Store the retrieved atmospheric pressure Dim g_lA As Long ' Store the retrieved altitude Sub Main() ' Main program starts here Dim fP As Float ' Store the input pressure value at sea level '----------------------------------------------------------------------------------------------------------- ' Do loop. The loop is terminated by entering a reasonable sea level. '---------------------------------------------------------------------------------------------------------- Do Debugin "Please enter the pressure at sea level: ", fP ' Display the inquiry message on the terminal Loop Until (fP>300 And fP<1100) ' The loop is terminated by entering a number in the range of 300-1100 Debug fP ' Display the last input value g_wP = Float2word(fP*10) ' Convert the input value into an integer myB.SetSeaLevelPressure(g_wP) ' Set the pressure at sea level myB.EnableRefreshEvent() ' Enable the measurement refresh event '------------------------------------------------------------------------------------------------------------- ' An infinite loop, while the program stays in this loop, it will receives new measurement values continuously ' and display the updated measurement value on the terminal window. '----------------------------------------------------------------------------------------------------------- Do Loop End Sub Event myB.RefreshEvent() ' The measurement refresh event myB.SetSeaLevelPressure(g_wP) ' Get the pressure value in the integer format myB.GetAltitude10Feet(g_lA) ' Get the altitude value in the integer format g_wP = g_wP \ 10 ' Convert the unit of the pressure into mBar. g_lA = g_lA \ 10 ' Convert the unit of the altitude into feet Debug CSRXY(1, 3), "Pressure: ", %DEC4 g_wP ' Display the pressure value on the terminal window Debug CSRXY(1, 4), "Altitude: ", %DEC4 g_lA ' Display the altitude value on the terminal window End Event