#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include "GyverButton.h"
#include <BME280I2C.h>
#define BTN_PIN 3
#define BASE_PERIOD 675000
#define MIN_VAL 990
#define MAX_VAL 1035
LiquidCrystal_I2C lcd(0x27, 20, 4);
GButton butt1(BTN_PIN);
BME280I2C bme;
uint32_t tmr1, tmr2;
uint32_t set_period = BASE_PERIOD;
int16_t plot_array[20];
uint16_t base_array[128];
int16_t value, delta;
byte interval = 1 ;
void setup() {
read_all();
attachInterrupt(1, isr, CHANGE);
butt1.setDebounce(80);
butt1.setTimeout(300);
lcd.init();
lcd.backlight();
lcd.clear();
Wire.begin();
if (!bme.begin()) { // Initialization of the BME280 sensor
lcd.setCursor(3, 1);
lcd.print(F("NIE WIDZE CZUJKI"));
lcd.setCursor(7, 2);
lcd.print(F("BME280"));
while (1);
}
if (!digitalRead(BTN_PIN)) {
for (byte i = 0; i < 128; i++) base_array[i] = 0;
update_all();
lcd.setCursor(4, 1);
lcd.print(F("KASUJ HISTORIE"));
lcd.setCursor(8, 2);
lcd.print(F("<OK>"));
}
while (!digitalRead(BTN_PIN));
lcd.clear();
initPlot();
float pres, temp, hum;
bme.read(pres, temp, hum);
value = round(pres);
base_array[0] = value;
get_data();
}
void isr() {
butt1.tick();
}
void loop() {
butt1.tick();
if (butt1.isClick()) {
interval *= 2;
if (interval > 8) interval = 1;
set_period = BASE_PERIOD * interval;
get_data();
}
if (millis() - tmr1 >= BASE_PERIOD) {
tmr1 = millis();
for (int i = 126; i >= 0; i--) {
base_array[i + 1] = base_array[i];
}
float pres, temp, hum;
bme.read(pres, temp, hum);
value=round(pres);
base_array[0] = value;
update_all();
}
if (millis() - tmr2 >= set_period) {
tmr2 = millis();
get_data();
}
}
void get_data() {
for (int i = 15; i >= 0; i--) {
drawPlot(0, 3, 16, 4, MIN_VAL, MAX_VAL, (base_array[i * interval]));
}
delta = ((base_array[0]) - (base_array[15 * interval]));
screen_data(value, delta, (interval * 3));
}
void screen_data(int value, int delta, byte interval) {
lcd.setCursor(16, 0);
lcd.print(int(value));
lcd.setCursor(17, 2);
if (delta == value) delta = 0;
if (delta > 0) {
lcd.print("+");
} else if (delta < 0) {
lcd.print("-");
} else if (delta == 0) {
lcd.print(" ");
}
lcd.setCursor(18, 2);
lcd.print(abs(delta));
if (abs(delta) < 10) {
lcd.setCursor(19, 2);
lcd.print(" ");
}
lcd.setCursor(17, 1);
lcd.print("hPa");
lcd.setCursor(17, 3);
lcd.print(interval);
(interval < 10) ? lcd.print("h ") : lcd.print("h");
}
void initPlot() {
byte row8[8] = {0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111};
byte row7[8] = {0b00000, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111};
byte row6[8] = {0b00000, 0b00000, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111};
byte row5[8] = {0b00000, 0b00000, 0b00000, 0b11111, 0b11111, 0b11111, 0b11111, 0b11111};
byte row4[8] = {0b00000, 0b00000, 0b00000, 0b00000, 0b11111, 0b11111, 0b11111, 0b11111};
byte row3[8] = {0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b11111, 0b11111, 0b11111};
byte row2[8] = {0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b11111, 0b11111};
byte row1[8] = {0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b00000, 0b11111};
lcd.createChar(0, row8);
lcd.createChar(1, row1);
lcd.createChar(2, row2);
lcd.createChar(3, row3);
lcd.createChar(4, row4);
lcd.createChar(5, row5);
lcd.createChar(6, row6);
lcd.createChar(7, row7);
}
void drawPlot(byte pos, byte row, byte width, byte height, int min_val, int max_val, int fill_val) {
for (byte i = 0; i < width; i++) {
plot_array[i] = plot_array[i + 1];
}
fill_val = constrain(fill_val, min_val, max_val);
plot_array[width - 1] = fill_val;
for (byte i = 0; i < width; i++) {
int infill, fract;
infill = floor((float)(plot_array[i] - min_val) / (max_val - min_val) * height * 10);
fract = (infill % 10) * 8 / 10;
infill = infill / 10;
for (byte n = 0; n < height; n++) {
if (n < infill && infill > 0) {
lcd.setCursor(i, (row - n));
lcd.write(0);
}
if (n >= infill) {
lcd.setCursor(i, (row - n));
if (fract > 0) lcd.write(fract);
else lcd.write(16);
for (byte k = n + 1; k < height; k++) {
lcd.setCursor(i, (row - k));
lcd.write(16);
}
break;
}
}
}
}
void update_all() {
eeprom_update_block((void*)&base_array, 0, sizeof(base_array));
}
void read_all() {
eeprom_read_block((void*)&base_array, 0, sizeof(base_array));
}
Comments
. I don't think I understand you quite well, but for a foreigner you handle Polish quite well. A little more and you'll be ok. As for "hardware" - you could also think about some ESP32, already with... [Read more]
For such small changes in the graph, you could try displaying it on an automatic scale. This looks more dynamic (pictorial). [Read more]
. Super. Please quote me an ESP32 with already built-in display of the same - or larger size, at a similar price. I would be happy to buy a 4x20 OLED for 50pln in the BIG version. Will you provide a link... [Read more]
. You've written that you've rewritten a ready-made one, so keep trying to make modifications yourself. . You can dream on, or take matters into your own hands :) . I am an amateur with no connection... [Read more]
ESP with OLed from 35pln, depending on the size, even 2" TFT, add a BME280 connection, somehow it is possible, software is a piece of cake, ESPEasy is even possible to throw the readings on the server... [Read more]
. That what? [Read more]
My understanding is this: The author of the topic found the barometer in an online shop for 50pln and ordered it. The seller realised that the price displayed was wrong and that the barometer actually... [Read more]
This may have been the case, but juxtaposed with the next two cases, it looks like an invention of the author rather than actual problems related to the purchase of three barometers consecutively. In addition,... [Read more]
. I stated at the beginning the reason why I got pissed....m and instead of buying more junk, I looked and did. One of the barometers purchased is lying under the table still waiting for a return label.... [Read more]
. Maybe not the first, but it's a fact. Consumer visits to this section are not that uncommon at all. I understand the comparison of the presented design with factory equipment. I just don't know what... [Read more]