...
Barometric Sensorin käyttöönotto
Tämän esimerkin .avulla saat NXT näyttöön näkyviin vallitsevan ilmanpaineen ja lämpötilan eri yksiköissä.
Code Block |
---|
koodi #pragma config(Sensor, S2, HTBM, sensorI2CCustom) #include "drivers/HTBM-driver.h" //download and include the drivers, more in metropolia wiki task main () { int pressmInHg = 0; float presshPa = 0.0; float pressPsi = 0.0; float tempC = 0.0; float tempF = 0.0; nxtDisplayCenteredBigTextLine(3, "WAIT"); wait1Msec(2000); while (true) { eraseDisplay(); // Read the sensor's data pressmInHg = HTBMreadMInHg(HTBM); // Pressure in 1/1000th of an inch Hg presshPa = HTBMreadhPa(HTBM); // Pressure in hecto Pascal pressPsi = HTBMreadPsi(HTBM); // Pressure in Pounds per square inch tempC = HTBMreadTemp(HTBM); // Temp in Celcius tempF = HTBMreadTempF(HTBM); // Temp in Fahrenheit nxtDisplayTextLine(0, "%5d mInHg", pressmInHg); nxtDisplayTextLine(2, "%5.1f hPa", presshPa); nxtDisplayTextLine(4, "%5.1f PSI", pressPsi); nxtDisplayTextLine(6, "%3.1f C", tempC); nxtDisplayTextLine(7, "%3.1f F", tempF); wait1Msec(100); } } |