thisreading < numreadings;thisreading ++){
读数[ thisreading ] = 0;
}
/ * * /
如果初始化传感器!BMP。begin())
{
/有个问题检测…请检查连接* /
串口打印(“抱歉,没有BMP085检测…检查你的接线或I2C地址!”);
while(1);
}</p><p> //Displaying
lcd.begin(16, 2); //initalising size of display (16 collumns, 2 rows)
lcd.setCursor(0,0); //set cursor to first row and first collumn
lcd.print("Temp:");
lcd.setCursor(0,1);
lcd.print("Pres:");</p><p>}</p><p>/**************************************************************************/
/*
Arduino loop function, called once 'setup' is complete (your own code
should go here)
*/
/**************************************************************************/
void loop(void) {
/* Get a new sensor event */
sensors_event_t event;
bmp.getEvent(&event);
/* Display the results (barometric pressure is measure in hPa) */
if (event.pressure)
{
/* Display atmospheric pressue in hPa */
Serial.print("Pressure: ");
Serial.print(event.pressure);
Serial.println(" hPa");
/* Calculating altitude with reasonable accuracy requires pressure *
* sea level pressure for your position at the moment the data is *
* conver泰德,以及环境温度在摄氏度
* *。如果你没有这些价值观,一个“通用”的价值
* * 1013.25 hPa可用(定义为sensors_pressure_sealevelhpa *
*传感器。H),但这并不是理想的,从一天到另一天给
变* *结果。* * * *
通常可以通过看天气
*网站或从环境信息中心附近的任何大*
机场找到当前气压值。*
* *
* For example, for Paris, France you can check the current mean *
* pressure and sea level at: <a href="http://bit.ly/16Au8ol" rel="nofollow"> http://bit.ly/16Au8ol </a> */
/* First we get the current temperature from the BMP085 */
float temperature;
bmp.getTemperature(&temperature);
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" C");</p><p> /* Then convert the atmospheric pressure, and SLP to altitude */
/* Update this next line with the current SLP for better results */
float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA;
Serial.print("Altitude: ");
Serial.print(bmp.pressureToAltitude(seaLevelPressure,
event.pressure));
Serial.println(" m");
Serial.println("");</p><p> lcd.setCursor(5,0);
lcd.print(temperature);
lcd.print((char)223);
lcd.print("C ");
</p><p> // subtract the last reading:
total = total - readings[readIndex];
// read from the sensor:
readings[readIndex] = event.pressure;
// add the reading to the total:
total = total + readings[readIndex];
// advance to the next position in the array:
readIndex = readIndex + 1;</p><p> // if we're at the end of the array...
if (readIndex >= numReadings) {
// ...wrap around to the beginning:
readIndex = 0;
}</p><p> // calculate the average:
average = total / numReadings;</p><p> delay(1);
lcd.setCursor(5,1);
lcd.print(average); // print average pressure
lcd.print("hPa");
}
else
{
Serial.println("Sensor error");
}
delay(0);
}</p>