//#include <Adafruit_BME280.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 20, 4);
//Adafruit_BME280 bme; // I2C
// 6 messages, 0-5
const char* text[] = {"-", "Sun", "Sun/Cloud", "Cloud", "Sun/Cloud/Rain", "Cloud/Rain"};
// mapping array 0, Zf(1-9), Zs(10-19), Zr(20-32). 33 messages, 0-32
byte msgNum[] = {0, // 0
1, 1, 2, 2, 3, 4, 4, 5, 5, // Zf (1-9)
1, 1, 2, 2, 4, 4, 5, 5, 5, 5, // Zs (10-19)
1, 1, 2, 2, 3, 5, 3, 3, 3, 3, 5, 5, 5 // Zr (20-32)
};
// Pressure array has 9 elements to fill.
// e.g. loopRepeat=5, time to fill 9 elements = 5 x 9 = 45 seconds
// e.g. loopRepeat=200, time = 1800 seconds (0.5 hr)
// e.g. loopRepeat=400, time = 3600 seconds (1 hr)
// e.g. loopRepeat=600, time = 5400 seconds (1.5 hr)
// e.g. loopRepeat=800, time = 7200 seconds (2 hr)
// e.g. loopRepeat=1000, time = 9000 seconds (2.5 hr)
// e.g. loopRepeat=1200, time = 10800 seconds (3 hr)
#define loopRepeat 3
char s[50];
float pressure[9] = {0};
float P, P0, Pn;
int Z;
int r;
bool colon;
void setup() {
// put your setup code here, to run once:
//bme.begin(0x76);
lcd.init();
lcd.backlight();
}
void loop() {
// put your main code here, to run repeatedly:
//P = bme.readPressure() / 100.0; // Pressure reading from sensor
P = 1009.25; // Dummy pressure value
if (r == 0) {
for (int a = 8; a > 0; a--) pressure[a] = pressure[a - 1];
pressure[0] = P; // Pressure reading from sensor
// Calc averages of pressures.
Pn = (pressure[6] + pressure[7] + pressure[8]) / 3.0; // Older values
P0 = (pressure[0] + pressure[1] + pressure[2]) / 3.0; // Newer values
if (P0 > 985 && P0 < 1050 && (Pn - P0) > 1.6) { // Pressure fall
Z = 127 - 0.18 * P0;
if (Z < 1 || Z > 9) Z = 0;
}
if (P0 > 960 && P0 < 1033 && abs(Pn - P0) < 1.6) { // Pressure steady
Z = 144 - 0.13 * P0;
if (Z < 10 || Z > 19) Z = 0;
}
if (P0 > 947 && P0 < 1030 && (P0 - Pn) > 1.6) { // Pressure rise
Z = 185 - 0.16 * P0;
if (Z < 20 || Z > 32) Z = 0;
}
if (P0 == 0 || Pn == 0) Z = 0;
}
lcd.setCursor(0, 0);
lcd.print(P);
lcd.print("mb ");
lcd.print(r * 100 / loopRepeat);
lcd.print("% ");
lcd.setCursor(0, 1);
lcd.print("P0: ");
lcd.print(P0);
lcd.print("mb avg ");
lcd.setCursor(0, 2);
lcd.print("Pn: ");
lcd.print(Pn);
lcd.print("mb avg ");
lcd.setCursor(0, 3);
lcd.print("Z:");
lcd.print(Z);
lcd.print(" ");
lcd.print(text[msgNum[Z]]);
lcd.print(" ");
lcd.setCursor(19, 0);
lcd.print(colon ? "." : " ");
colon = !colon;
delay(1000);
r++;
r = r % loopRepeat;
}