Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- Fedor Chervyakov
- Date:
- 2019-08-15
- Revision:
- 1:667b9825e7ee
- Parent:
- 0:22a4f6c99d74
- Child:
- 2:45ed62566694
File content as of revision 1:667b9825e7ee:
/* BME280 BLE senior -- main.cpp
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Copyright 2019 Fedor Chervyakov
*/
#include "mbed.h"
#include "bme280_wrapper.h"
AnalogIn lm35_input(A0);
void print_sensor_data(struct bme280_data *comp_data)
{
float temp, press, hum;
#ifdef BME280_FLOAT_ENABLE
temp = comp_data->temperature;
press = 0.01 * comp_data->pressure;
hum = comp_data->humidity;
#else
#ifdef BME280_64BIT_ENABLE
temp = 0.01f * comp_data->temperature;
press = 0.0001f * comp_data->pressure;
hum = 1.0f / 1024.0f * comp_data->humidity;
#else
temp = 0.01f * comp_data->temperature;
press = 0.01f * comp_data->pressure;
hum = 1.0f / 1024.0f * comp_data->humidity;
#endif
#endif
printf("BME280 %0.2lf deg C, %0.2lf hPa, %0.2lf%%\n", temp, press, hum);
}
// main() runs in its own thread in the OS
int main()
{
struct bme280_data comp_data;
BME280 bme280(I2C_SDA, I2C_SCL);
while (true) {
bme280.force_measurement();
printf("LM35 %.2f deg C; ", lm35_input / 0.01 * 3.3);
print_sensor_data(&bme280.comp_data);
wait(5);
}
}