Une nouvelle et dernière mise à jour avec des changements dans le découpage des pressions et l'affectation aux couleurs. Je pense que c'est mieux comme ceci.
Voici le code de cette ultime release de la version 1, nom de code "Epic Ernest" :
Author: Guy Vanoverbeke @GuyVano
Program last update (dd/mm/yyyy) : 16/02/2021 - V.1 R.5 C.0 - Release "Epic Ernest"
Arduino IDE V1.8.13
Board: Arduino UNO R3
Function: Using a BME280 sensor, display the range of barometric pressure and trend on a single RGB LED.
Fixed red: QNH <= 995 (Barometric pressure at sea level is lower or equal to 995 hPa)
Fixed purple: 996 <= QNH <= 1005 hPa
Fixed indigo: 1006 <= QNH <= 1010 hPa
Fixed yellow: 1011 <= QNH <= 1015 hPa
Fixed green: 1016 <= QNH <= 1020 hPa
Fixed blue: 1021 <= QNH <= 1030 hPa
Fixed ice white: 1031 <= QNH
Short green flashes each 30 seconds: barometric pressure has increased recently (at least +0.2 hPa in the last 15 minutes).
Short blue flashes each 30 seconds: barometric pressure has decreased recently (at least -0.2 in the last 15 minutes).
Short red flashes each 30 seconds : barometric pressure fast falling warning (at least -0.5 hPa in the last 15 mn).
Disclaimer:
This program (in other words: this code, this software or this application) is a personal creation made as part of a hobby
and it is given without guarantee of any kind and no support is provided. It is free of rights
and can be reused freely as you wish.
*/
#include <Wire.h>
//
// I2C Temperature, humidity and barometric pressure sensor
//
#include <Adafruit_BME280.h>
Adafruit_BME280 bme;
//
// Define the 3 pins of the RGB LED
//
const byte pblueled = 9;
const byte pgreenled = 10;
const byte predled = 11;
//
const int myaltitude = 186; // altitude above sea level en meter
const boolean acnt = false; // true for serial monitor/debug
//
// variables
//
int qfe = 0; // locale barometric pressure qfe in daPa (decaPascal)
int dqfe = 0; // Local barometric pressure difference between 2 sensor reads cycle (in daPa)
int pqfe = 0; // Local barometric pressure of the previous read cycle (in daPa)
int qnh = 0; // Barometric pressure calculated at sea level (in hPa)
int sdqfe = 0; // sum dqfe
int i = 0; // Loop control
boolean fqfeup = false; // flag qnh up
boolean fqfedown = false; // flag qnh down
boolean fqfewarn = false; // flag qnh fast down
byte cpt = 0; // cycle counter
int tdqfe[30] = {}; // history table of dqfe
//
void setup()
{
if (acnt) {
Serial.begin(9600);
Serial.println(" ");
Serial.println("*******************************************************");
Serial.println(" ");
Serial.println("BARO1-5-guyvano restarted! V.1 R.5 C.0 'Epic Ernest'");
}
//
// Define pins modes
//
pinMode(predled, OUTPUT);
pinMode(pgreenled, OUTPUT);
pinMode(pblueled, OUTPUT);
//
// Sensor
//
bme.begin(0x76); // address of the BME280 I2C sensor
//
// Show the colors used from the lower to higher pressures
//
// Red
digitalWrite(predled, HIGH);
digitalWrite(pgreenled, LOW);
digitalWrite(pblueled, LOW);
delay(1000);
// Purple
digitalWrite(predled, HIGH);
digitalWrite(pgreenled, LOW);
digitalWrite(pblueled, HIGH);
delay(1000);
// Indigo
digitalWrite(predled, LOW);
delay(1000);
// Yellow
digitalWrite(predled, HIGH);
digitalWrite(pgreenled, HIGH);
digitalWrite(pblueled, LOW);
delay(1000);
// Green
digitalWrite(predled, LOW);
delay(1000);
// Ice Blue
digitalWrite(pgreenled, HIGH);
digitalWrite(pblueled, HIGH);
delay(1000);
// Ice white
digitalWrite(predled, HIGH);
delay(1000);
digitalWrite(pblueled, LOW);
digitalWrite(predled, LOW);
digitalWrite(pgreenled, LOW);
delay(450);
//
// Let's go! letter R in morse (Ready!) .-.
//
digitalWrite(pgreenled, HIGH);
delay(150);
digitalWrite(pgreenled, LOW);
delay(200);
digitalWrite(pgreenled, HIGH);
delay(450);
digitalWrite(pgreenled, LOW);
delay(200);
digitalWrite(pgreenled, HIGH);
delay(150);
digitalWrite(pgreenled, LOW);
delay(450);
//
qfe = (bme.readPressure() + 5.0F) / 10.0F; // locale pressure qfe in daPa rounded
pqfe = qfe;
// initialize history table of the 30 dqfe values with 0
for (i = 0; i < 30; i++ ) {
tdqfe[i] = 0;
}
cpt = 0;
}
void loop()
{
qfe = (bme.readPressure() + 5.0F) / 10.0F;
qnh = (qfe / 10.0F) + (myaltitude * 0.1205F);
dqfe = qfe - pqfe;
tdqfe[cpt] = dqfe;
//
sdqfe = 0;
for (i = 0; i < 30; i++ ) {
sdqfe = sdqfe + tdqfe[i];
}
//
fqfeup = false;
fqfedown = false;
fqfewarn = false;
//
if ( 1 < sdqfe) {
fqfeup = true;
}
//
if (sdqfe < -1) {
fqfedown = true;
}
//
if (sdqfe < -4) {
fqfewarn = true;
fqfedown = false;
}
//
// UP : Green flashing
//
if (fqfeup) {
digitalWrite(pblueled, LOW);
digitalWrite(predled, LOW);
digitalWrite(pgreenled, LOW);
delay(450);
for (i = 0; i < 5; i++ ) {
// flash U in morse code ..-
digitalWrite(pgreenled, HIGH);
delay(150);
digitalWrite(pgreenled, LOW);
delay(150);
digitalWrite(pgreenled, HIGH);
delay(150);
digitalWrite(pgreenled, LOW);
delay(150);
digitalWrite(pgreenled, HIGH);
delay(450);
digitalWrite(pgreenled, LOW);
delay(450);
}
}
//
// DOWN : Blue flashing
//
if (fqfedown) {
digitalWrite(pblueled, LOW);
digitalWrite(pgreenled, LOW);
digitalWrite(predled, LOW);
delay(450);
for (i = 0; i < 5; i++ ) {
// flash D in morse code -..
digitalWrite(pblueled, HIGH);
delay(450);
digitalWrite(pblueled, LOW);
delay(150);
digitalWrite(pblueled, HIGH);
delay(150);
digitalWrite(pblueled, LOW);
delay(150);
digitalWrite(pblueled, HIGH);
delay(150);
digitalWrite(pblueled, LOW);
delay(450);
}
}
//
// FAST FALLING WARNING : Red flashing
//
if (fqfewarn) {
digitalWrite(pblueled, LOW);
digitalWrite(pgreenled, LOW);
digitalWrite(predled, LOW);
delay(450);
for (i = 0; i < 5; i++ ) {
// flash W in morse code .--
digitalWrite(predled, HIGH);
delay(150);
digitalWrite(predled, LOW);
delay(150);
digitalWrite(predled, HIGH);
delay(450);
digitalWrite(predled, LOW);
delay(150);
digitalWrite(predled, HIGH);
delay(450);
digitalWrite(predled, LOW);
delay(450);
}
}
//
// Long light on, depending of the qnh range
//
// QNH <= 995 : Red
//
if (qnh <= 995) {
digitalWrite(predled, HIGH);
digitalWrite(pgreenled, LOW);
digitalWrite(pblueled, LOW);
}
//
// 996 <= QNH <= 1005 : Purple
//
if ((996 <= qnh) & (qnh <= 1005)) {
digitalWrite(predled, HIGH);
digitalWrite(pgreenled, LOW);
digitalWrite(pblueled, HIGH);
}
//
// 1006 <= QNH <= 1010 : Indigo
//
if ((1006 <= qnh) & (qnh <= 1010)) {
digitalWrite(predled, LOW);
digitalWrite(pgreenled, LOW);
digitalWrite(pblueled, HIGH);
}
//
// 1011 <= QNH <= 1015 : Yellow
//
if ((1011 <= qnh) & (qnh <= 1015)) {
digitalWrite(predled, HIGH);
digitalWrite(pgreenled, HIGH);
digitalWrite(pblueled, LOW);
}
//
// 1016 <= QNH <= 1020 : Green
//
if ((1016 <= qnh) & (qnh <= 1020)) {
digitalWrite(predled, LOW);
digitalWrite(pgreenled, HIGH);
digitalWrite(pblueled, LOW);
}
//
// 1021 <= QNH <= 1030 : Light Blue
//
if ((1021 <= qnh) & (qnh <= 1030)) {
digitalWrite(predled, LOW);
digitalWrite(pgreenled, HIGH);
digitalWrite(pblueled, HIGH);
}
//
// 1031 <= QNH : Ice White
//
if (1031 <= qnh) {
digitalWrite(predled, HIGH);
digitalWrite(pgreenled, HIGH);
digitalWrite(pblueled, HIGH);
}
//
// serial control values if acnt set to true
//
if (acnt) {
Serial.println(" ");
Serial.print("cpt:");
Serial.print(cpt);
Serial.print(", qnh:");
Serial.print(qnh);
Serial.print(", qfe:");
Serial.print(qfe);
Serial.print(", pqfe:");
Serial.print(pqfe);
Serial.print(", dqfe:");
Serial.print(dqfe);
Serial.print(", sdqfe:");
Serial.print(sdqfe);
Serial.print(", fqfeup:");
Serial.print(fqfeup);
Serial.print(", fqfedown:");
Serial.print(fqfedown);
Serial.print(", fqfewarn:");
Serial.print(fqfewarn);
/*
for (i = 0; i < 30; i++ ) {
Serial.print(", tdqfe[");
Serial.print(i);
Serial.print("]:");
Serial.print(tdqfe[i]);
}
*/
}
//
pqfe = qfe;
cpt = (cpt + 1) % 30; // cpt+1 modulo 30, cpt return to 0 after 29.
//
delay(30000); // 30000 means 30 seconds to wait before a new cycle
}
// End of the program BARO1-5-guyvano.ino - V.1 R.5 C.0 - Release "Epic Ernest" - Thanks for watching !