Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <Adafruit_Sensor.h>
- #include <Adafruit_BME280.h>
- #define LEDPERIOD 250 // 1/2 the LED blink rate
- #define READPERIOD 1000 // 1x sample rate
- #define SEALEVELPRESSURE_HPA (1013.25)
- Adafruit_BME280 bme;
- int ledState = HIGH;
- int
- unsigned long ledlastTime = 0;
- unsigned long readlastTime = 0;
- void setup() {
- Serial.begin(9600);
- Wire.begin();
- pinMode(LED_BUILTIN, OUTPUT);
- digitalWrite(LED_BUILTIN, ledState);
- if (!bme.begin(0x76)) {
- Serial.println("Could not find a valid BME280 sensor, check wiring!");
- while (1);
- }
- }
- void loop() {
- unsigned long lednow = millis();
- unsigned long readnow = millis();
- if(lednow - ledlastTime >= LEDPERIOD){
- ledlastTime = lednow;
- if (ledState == LOW){
- ledState = HIGH;
- }else{
- ledState = LOW;
- }
- }
- digitalWrite(LED_BUILTIN, ledState);
- if(readnow - readlastTime >= READPERIOD){
- readlastTime = readnow;
- Serial.print("Temperature = ");
- Serial.print(bme.readTemperature());
- Serial.println("*C");
- Serial.print("Pressure = ");
- Serial.print(bme.readPressure() / 100.0F);
- Serial.println("hPa");
- Serial.print("Approx. Altitude = ");
- Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
- Serial.println("m");
- Serial.print("Humidity = ");
- Serial.print(bme.readHumidity());
- Serial.println("%");
- Serial.println();
- }
- }
Add Comment
Please, Sign In to add comment