Compare commits

..

3 Commits

Author SHA1 Message Date
Kamil Siejka
90d98bf848 Początek menu zmiany interwału rejestrowania 2025-06-19 09:37:31 +02:00
Kamil Siejka
536b203cb7 Merge branch 'master' of ssh://gitea.kaczor.it:2222/sieja/Arduino 2025-06-19 09:37:08 +02:00
Kamil Siejka
4e1c4ff2f1 Wstepna wersja RGB na ESP32 2025-06-19 09:36:03 +02:00
2 changed files with 512 additions and 523 deletions

View File

@@ -11,7 +11,7 @@ TFT_eSPI tft = TFT_eSPI(); // domyślna konfiguracja z User_Setup.h
// obsługa przycisków zmieniających menu i LED // obsługa przycisków zmieniających menu i LED
//160x128 //160x128
#define Version "0.0.0" #define Version "0.0.1"
#include <SPI.h> #include <SPI.h>
#include <Wire.h> #include <Wire.h>
#include <Adafruit_GFX.h> #include <Adafruit_GFX.h>
@@ -162,8 +162,6 @@ void loop() {
} }
if (menu_number == 0 ) {//show menu if (menu_number == 0 ) {//show menu
tft.setTextSize(2); tft.setTextSize(2);
tft.drawString("GAIN:" + String(gainValue),0, 0); tft.drawString("GAIN:" + String(gainValue),0, 0);
@@ -177,11 +175,9 @@ void loop() {
delay(100); delay(100);
} }
// show calculated values
// //
if (menu_number == 1 || menu_number == 5 ) {//show calculated values if (menu_number == 1 || menu_number == 5 ) {//show calculated values
drawControls(); drawControls();
//tft.setRotation(0);
tft.drawString("Calculated Values",0,0); tft.drawString("Calculated Values",0,0);
tft.drawString("R:" + String(CalcRed),0, 20); tft.drawString("R:" + String(CalcRed),0, 20);
tft.drawString("O:" + String(CalcOrange),0, 39); tft.drawString("O:" + String(CalcOrange),0, 39);
@@ -202,163 +198,101 @@ void loop() {
tft.drawString("V:" + String(RawViolet),0, 115); tft.drawString("V:" + String(RawViolet),0, 115);
} }
//show relative calculated values graph
if (menu_number == 3 || menu_number == 7 ){
tft.setTextColor(TFT_WHITE, TFT_BLACK);
maxValue = 0.0;
minValue = 0.0;
for (int i = 0; i < 5; i++) {
maxValue = max(maxValue, ReadValues[i]);
}
HeightRed = int((CalcRed / maxValue) * GraphHeight);
HeightOrange = int((CalcOrange / maxValue) * GraphHeight);
HeightYellow = int((CalcYellow / maxValue) * GraphHeight);
HeightGreen = int((CalcGreen / maxValue) * GraphHeight);
HeightBlue = int((CalcBlue / maxValue) * GraphHeight);
HeightViolet = int((CalcViolet / maxValue) * GraphHeight);
for (int i = 0; i < 5; i++) {
maxValue = min(maxValue, ReadValues[i]);
}
tft.fillRect(minValue, 0, 240, maxValue-minValue, TFT_BLACK);
drawControls();
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.drawString("Relvative Calculated Values",0,0);
drawControls();
tft.fillRect(0 * GrapWidth, GraphHeight - HeightRed+8, GrapWidth, HeightRed, TFT_RED);
tft.fillRect(1 * GrapWidth + 1, GraphHeight - HeightOrange+8, GrapWidth, HeightOrange, TFT_ORANGE);
tft.fillRect(2 * GrapWidth + 2, GraphHeight - HeightYellow+8, GrapWidth, HeightYellow, TFT_YELLOW);
tft.fillRect(3 * GrapWidth + 3, GraphHeight - HeightGreen+8, GrapWidth, HeightGreen, TFT_GREEN);
tft.fillRect(4 * GrapWidth + 4, GraphHeight - HeightBlue+8, GrapWidth, HeightBlue, TFT_BLUE);
tft.fillRect(5 * GrapWidth + 5, GraphHeight - HeightViolet+8, GrapWidth, HeightViolet, TFT_MAGENTA);
tft.setCursor(1 * GrapWidth -10, 0);
////tft.setRotation(0);
// //show relative calculated values graph tft.setTextColor(TFT_BLACK, TFT_RED);
// if (menu_number == 3 || menu_number == 7 ){ tft.drawString(" R:",1 * GrapWidth -20, 120);
// maxValue = 0; tft.setTextColor(TFT_BLACK, TFT_ORANGE);
// drawControls(); tft.drawString(" O:",2 * GrapWidth -19, 120);
// ////tft.setRotation(0); tft.setTextColor(TFT_BLACK, TFT_YELLOW);
tft.drawString(" Y:",3 * GrapWidth -18, 120);
// for (int i = 0; i < 5; i++) { tft.setTextColor(TFT_BLACK, TFT_GREEN);
// maxValue = max(maxValue, ReadValues[i]); tft.drawString(" G:",4 * GrapWidth -17, 120);
// } tft.setTextColor(TFT_BLACK, TFT_BLUE);
// HeightRed = int((CalcRed / maxValue) * GraphHeight); tft.drawString(" B:",5 * GrapWidth -16, 120);
// HeightOrange = int((CalcOrange / maxValue) * GraphHeight); tft.setTextColor(TFT_BLACK, TFT_MAGENTA);
// HeightYellow = int((CalcYellow / maxValue) * GraphHeight); tft.drawString(" V:",6 * GrapWidth -15, 120);
// HeightGreen = int((CalcGreen / maxValue) * GraphHeight); maxValue = 0.0;
// HeightBlue = int((CalcBlue / maxValue) * GraphHeight); minValue = 0.0;
// HeightViolet = int((CalcViolet / maxValue) * GraphHeight); }
// tft.setCursor(1 * GrapWidth -10, 10);
// if (HeightRed >25){
// tft.setTextColor(BLACK);
// }
// tft.fillRect(0 * GrapWidth, GraphHeight - HeightRed, GrapWidth, HeightRed, RED);
// tft.fillRect(1 * GrapWidth + 1, GraphHeight - HeightOrange, GrapWidth, HeightOrange, ORANGE);
// tft.fillRect(2 * GrapWidth + 2, GraphHeight - HeightYellow, GrapWidth, HeightYellow, YELLOW);
// tft.fillRect(3 * GrapWidth + 3, GraphHeight - HeightGreen, GrapWidth, HeightGreen, GREEN);
// tft.fillRect(4 * GrapWidth + 4, GraphHeight - HeightBlue, GrapWidth, HeightBlue, BLUE);
// tft.fillRect(5 * GrapWidth + 5, GraphHeight - HeightViolet, GrapWidth, HeightViolet, MAGENTA);
// tft.setCursor(1 * GrapWidth -10, 0);
// if (HeightRed > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("R:");
// tft.setCursor(2 * GrapWidth -10, 0);
// if (HeightOrange > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("O:");
// tft.setCursor(3 * GrapWidth -10, 0);
// if (HeightYellow > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("Y:");
// tft.setCursor(4 * GrapWidth -10, 0);
// if (HeightGreen > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("G:");
// tft.setCursor(5 * GrapWidth -10, 0);
// if (HeightBlue > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("B:");
// tft.setCursor(6 * GrapWidth -10, 0);
// if (HeightViolet > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("V:");
// maxValue = 0.0;
// }
// //show relative raw data graph // //show relative raw data graph
// if (menu_number == 4 || menu_number == 8 ){ if (menu_number == 4 || menu_number == 8 ){
// maxValue = 0; tft.setTextColor(TFT_WHITE, TFT_BLACK);
// drawControls(); maxValue = 0.0;
// ////tft.setRotation(0); minValue = 0.0;
for (int i = 0; i < 5; i++) {
maxValue = max(maxValue, ReadValues[i]);
}
for (int i = 0; i < 5; i++) {
minValue = min(minValue, ReadValues[i]);
}
HeightRed = int(((RawRed + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight);
HeightOrange = int(((RawOrange + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight);
HeightYellow = int(((RawYellow + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight);
HeightGreen = int(((RawGreen + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight);
HeightBlue = int(((RawBlue + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight);
HeightViolet = int(((RawViolet + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight);
tft.fillRect(minValue, 0, 240, maxValue-minValue, TFT_BLACK);
drawControls();
tft.setTextColor(TFT_WHITE, TFT_BLACK);
tft.drawString("Relvative Raw Values",0,0);
// for (int i = 0; i < 5; i++) { tft.fillRect(0 * GrapWidth, GraphHeight - HeightRed+8, GrapWidth, HeightRed, TFT_RED);
// maxValue = max(maxValue, ReadValues[i]); tft.fillRect(1 * GrapWidth + 1, GraphHeight - HeightOrange+8, GrapWidth, HeightOrange, TFT_ORANGE);
// } tft.fillRect(2 * GrapWidth + 2, GraphHeight - HeightYellow+8, GrapWidth, HeightYellow, TFT_YELLOW);
// for (int i = 0; i < 5; i++) { tft.fillRect(3 * GrapWidth + 3, GraphHeight - HeightGreen+8, GrapWidth, HeightGreen, TFT_GREEN);
// minValue = min(minValue, ReadValues[i]); tft.fillRect(4 * GrapWidth + 4, GraphHeight - HeightBlue+8, GrapWidth, HeightBlue, TFT_BLUE);
// } tft.fillRect(5 * GrapWidth + 5, GraphHeight - HeightViolet+8, GrapWidth, HeightViolet, TFT_MAGENTA);
// HeightRed = int(((RawRed + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight); tft.setTextColor(TFT_BLACK, TFT_RED);
// HeightOrange = int(((RawOrange + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight); tft.drawString(" R:",1 * GrapWidth -20, 120);
// HeightYellow = int(((RawYellow + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight); tft.setTextColor(TFT_BLACK, TFT_ORANGE);
// HeightGreen = int(((RawGreen + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight); tft.drawString(" O:",2 * GrapWidth -19, 120);
// HeightBlue = int(((RawBlue + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight); tft.setTextColor(TFT_BLACK, TFT_YELLOW);
// HeightViolet = int(((RawViolet + abs(minValue)) / (maxValue + abs(minValue))) * GraphHeight); tft.drawString(" Y:",3 * GrapWidth -18, 120);
tft.setTextColor(TFT_BLACK, TFT_GREEN);
tft.drawString(" G:",4 * GrapWidth -17, 120);
// tft.setCursor(1 * GrapWidth -10, 10); tft.setTextColor(TFT_BLACK, TFT_BLUE);
// if (HeightRed >25){ tft.drawString(" B:",5 * GrapWidth -16, 120);
// tft.setTextColor(BLACK); tft.setTextColor(TFT_BLACK, TFT_MAGENTA);
// } tft.drawString(" V:",6 * GrapWidth -15, 120);
maxValue = 0.0;
// tft.fillRect(0 * GrapWidth, GraphHeight - HeightRed, GrapWidth, HeightRed, RED); minValue = 0.0;
// tft.fillRect(1 * GrapWidth + 1, GraphHeight - HeightOrange, GrapWidth, HeightOrange, ORANGE); }
// tft.fillRect(2 * GrapWidth + 2, GraphHeight - HeightYellow, GrapWidth, HeightYellow, YELLOW);
// tft.fillRect(3 * GrapWidth + 3, GraphHeight - HeightGreen, GrapWidth, HeightGreen, GREEN);
// tft.fillRect(4 * GrapWidth + 4, GraphHeight - HeightBlue, GrapWidth, HeightBlue, BLUE);
// tft.fillRect(5 * GrapWidth + 5, GraphHeight - HeightViolet, GrapWidth, HeightViolet, MAGENTA);
// tft.setCursor(1 * GrapWidth -10, 0);
// if (HeightRed > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("R");
// tft.setCursor(2 * GrapWidth -10, 0);
// if (HeightOrange > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("O");
// tft.setCursor(3 * GrapWidth -10, 0);
// if (HeightYellow > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("Y");
// tft.setCursor(4 * GrapWidth -10, 0);
// if (HeightGreen > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("G");
// tft.setCursor(5 * GrapWidth -10, 0);
// if (HeightBlue > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("B");
// tft.setCursor(6 * GrapWidth -10, 0);
// if (HeightViolet > 28){
// tft.setTextColor(BLACK);
// }else {
// tft.setTextColor(WHITE);
// }
// tft.println("V");
// maxValue = 0.0;
// }
delay(100); delay(100);
if (menu_number > 4 ) { if (menu_number > 4 ) {
@@ -399,25 +333,25 @@ void loop() {
// //data haverest //data haverest
// RawRed = sensor.getRed(); RawRed = sensor.getRed();
// RawOrange = sensor.getOrange(); RawOrange = sensor.getOrange();
// RawYellow = sensor.getYellow(); RawYellow = sensor.getYellow();
// RawGreen = sensor.getGreen(); RawGreen = sensor.getGreen();
// RawBlue = sensor.getBlue(); RawBlue = sensor.getBlue();
// RawViolet = sensor.getViolet(); RawViolet = sensor.getViolet();
// CalcRed = sensor.getCalibratedRed(); CalcRed = sensor.getCalibratedRed();
// CalcOrange = sensor.getCalibratedOrange(); CalcOrange = sensor.getCalibratedOrange();
// CalcYellow = sensor.getCalibratedYellow(); CalcYellow = sensor.getCalibratedYellow();
// CalcGreen = sensor.getCalibratedGreen(); CalcGreen = sensor.getCalibratedGreen();
// CalcBlue = sensor.getCalibratedBlue(); CalcBlue = sensor.getCalibratedBlue();
// CalcViolet = sensor.getCalibratedViolet(); CalcViolet = sensor.getCalibratedViolet();
// ReadValues[0] = CalcRed; ReadValues[0] = CalcRed;
// ReadValues[1] = CalcOrange; ReadValues[1] = CalcOrange;
// ReadValues[2] = CalcYellow; ReadValues[2] = CalcYellow;
// ReadValues[3] = CalcGreen; ReadValues[3] = CalcGreen;
// ReadValues[4] = CalcBlue; ReadValues[4] = CalcBlue;
// ReadValues[5] = CalcViolet; ReadValues[5] = CalcViolet;
} }

View File

@@ -1,3 +1,4 @@
//Płytka: "FireBeetle-ESP32"
#include <SPI.h> #include <SPI.h>
#include <Wire.h> #include <Wire.h>
#include <Adafruit_GFX.h> #include <Adafruit_GFX.h>
@@ -9,21 +10,21 @@
#include "SD.h" #include "SD.h"
#include "SPI.h" #include "SPI.h"
#define Version "0.46" #define Version "0.47"
#define WIRE Wire #define WIRE Wire
#define DHTTYPE DHT22 #define DHTTYPE DHT22
#define DHTPIN 4 //GPIO04 D4 #define DHTPIN 4 //GPIO04 D4
#define SD_CS 5 //GPIO05 D5 #define SD_CS 5 //GPIO05 D5
#define BTN_UP 33 //GPIO33 D33 #define BTN_UP 33 //GPIO33 D33
#define BTN_ENTER 34 //GPIO34 D34 #define BTN_ENTER 34 //GPIO34 D34
#define BTN_DOWN 35 //GPIO35 D35 #define BTN_DOWN 35 //GPIO35 D35
#define VOLT_IN 36 //GPIO36 VP #define VOLT_IN 36 //GPIO36 VP
#define FAN_PIN 14 //GPIO36 D14 #define FAN_PIN 14 //GPIO36 D14
#define DHTPIN_L 13 //GPIO36 D13 #define DHTPIN_L 13 //GPIO36 D13
#define DHTPIN_M 17 //GPIO36 D17 #define DHTPIN_M 17 //GPIO36 D17
#define DHTPIN_H 16 //GPIO36 D16 #define DHTPIN_H 16 //GPIO36 D16
@@ -34,7 +35,7 @@
//MISO //GPIO19 D19 //MISO //GPIO19 D19
//SCK //GPIO18 D18 //SCK //GPIO18 D18
const float voltageDividerFactor = 1.51;//1.56; const float voltageDividerFactor = 1.51; //1.56;
const float adcMaxVoltage = 3.3; const float adcMaxVoltage = 3.3;
const int adcResolution = 4095; const int adcResolution = 4095;
@@ -80,7 +81,9 @@ int dayss;
int months; int months;
int years; int years;
int intervalTempWrite = 1; //##########################################################################################################################
int intervalTempIdx = 3;
int intervalTempWrite = 0;
int minsToSet = -1; int minsToSet = -1;
int hoursToSet = -1; int hoursToSet = -1;
@@ -89,7 +92,7 @@ int adcVoltValue;
float measuredVoltage = 0; float measuredVoltage = 0;
float batteryVoltage = 0; float batteryVoltage = 0;
float quickBatteryVoltage = 0; float quickBatteryVoltage = 0;
float quickBatteryVoltage2 = 0; float quickBatteryVoltage2 = 0;
float quickBatteryVoltage3 = 0; float quickBatteryVoltage3 = 0;
float quickBatteryVoltage4 = 0; float quickBatteryVoltage4 = 0;
@@ -102,14 +105,14 @@ int estMins = 0;
int batteryPercent = 0; int batteryPercent = 0;
int batteryBarWidth = 0; int batteryBarWidth = 0;
char dateString[21]; char dateString[21];
std::string chrgState; std::string chrgState;
unsigned long previousMillis = 0; unsigned long previousMillis = 0;
const unsigned long interval = 1000; const unsigned long interval = 1000;
unsigned long currentMillis = millis(); unsigned long currentMillis = millis();
String formatNumber(float number, int decimalPlaces = 1 ) { String formatNumber(float number, int decimalPlaces = 1) {
String str = String(number, decimalPlaces); String str = String(number, decimalPlaces);
str.replace('.', ','); str.replace('.', ',');
if (number < 10) { if (number < 10) {
@@ -134,9 +137,9 @@ float voltageToPercentage(float voltage) {
// Reprezentatywne punkty (wolt, procent) // Reprezentatywne punkty (wolt, procent)
const int nPoints = 9; const int nPoints = 9;
// Napięcia uporządkowane malejąco // Napięcia uporządkowane malejąco
float vPoints[nPoints] = {4.06, 4.00, 3.95, 3.90, 3.85, 3.80, 3.70, 3.45, 2.75}; float vPoints[nPoints] = { 4.06, 4.00, 3.95, 3.90, 3.85, 3.80, 3.70, 3.45, 2.75 };
// Odpowiednie poziomy naładowania // Odpowiednie poziomy naładowania
float pPoints[nPoints] = {100, 95, 90, 80, 70, 60, 50, 10, 0}; float pPoints[nPoints] = { 100, 95, 90, 80, 70, 60, 50, 10, 0 };
if (voltage >= vPoints[0]) if (voltage >= vPoints[0])
return pPoints[0]; return pPoints[0];
if (voltage <= vPoints[nPoints - 1]) if (voltage <= vPoints[nPoints - 1])
@@ -149,7 +152,7 @@ float voltageToPercentage(float voltage) {
return pPoints[i + 1] + fraction * (pPoints[i] - pPoints[i + 1]); return pPoints[i + 1] + fraction * (pPoints[i] - pPoints[i + 1]);
} }
} }
return 0; // Domyślnie choć powinno się tu już nie dojść return 0; // Domyślnie choć powinno się tu już nie dojść
} }
// Funkcja liniowej interpolacji // Funkcja liniowej interpolacji
@@ -175,16 +178,16 @@ float chargeVoltageToPercentage(float voltage) {
4.22 // 100% 4.22 // 100%
}; };
float pPoints[nPoints] = { float pPoints[nPoints] = {
0, // 4.03 V 0, // 4.03 V
1, // 4.06 V 1, // 4.06 V
5, // 4.12 V 5, // 4.12 V
10, // 4.14 V 10, // 4.14 V
30, // 4.16 V 30, // 4.16 V
60, // 4.18 V 60, // 4.18 V
80, // 4.19 V 80, // 4.19 V
95, // 4.20 V 95, // 4.20 V
98, // 4.21 V 98, // 4.21 V
100 // 4.22 V 100 // 4.22 V
}; };
// 1. Jeśli napięcie jest poniżej najniższego punktu, zwróć minimalny procent // 1. Jeśli napięcie jest poniżej najniższego punktu, zwróć minimalny procent
@@ -215,9 +218,10 @@ void setup() {
if (!rtc.begin()) { if (!rtc.begin()) {
Serial.println("Nie znaleziono DS3231 RTC!"); Serial.println("Nie znaleziono DS3231 RTC!");
while (1); // Zatrzymaj program, jeśli RTC nie jest dostępny while (1)
; // Zatrzymaj program, jeśli RTC nie jest dostępny
} }
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32 display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32
display.setTextSize(1); display.setTextSize(1);
display.setTextColor(SSD1306_WHITE); display.setTextColor(SSD1306_WHITE);
display.clearDisplay(); display.clearDisplay();
@@ -226,10 +230,21 @@ void setup() {
display.setCursor(60, 0); display.setCursor(60, 0);
display.println(Version); display.println(Version);
display.setCursor(0, 8); display.setCursor(0, 8);
if (intervalTempIdx = 1) {
intervalTempWrite = 1;
} else if (intervalTempIdx = 2) {
intervalTempWrite = 5;
} else if (intervalTempIdx = 3) {
intervalTempWrite = 15;
} else if (intervalTempIdx = 4) {
intervalTempWrite = 60;
} else {
intervalTempWrite = 360;
}
display.println("Interval:"); display.println("Interval:");
display.setCursor(60, 8); display.setCursor(80, 8);
display.println(intervalTempWrite); display.println(intervalTempWrite);
display.setCursor(70, 8); display.setCursor(90, 8);
display.println("min"); display.println("min");
display.setCursor(0, 16); display.setCursor(0, 16);
@@ -239,7 +254,7 @@ void setup() {
display.setCursor(0, 24); display.setCursor(0, 24);
display.println("Battery: "); display.println("Battery: ");
display.setCursor(55, 24); display.setCursor(55, 24);
display.println(int(floor(float(battLifeMins)/60))); display.println(int(floor(float(battLifeMins) / 60)));
display.setCursor(70, 24); display.setCursor(70, 24);
display.println("h"); display.println("h");
display.display(); display.display();
@@ -248,9 +263,9 @@ void setup() {
dhtL.begin(); dhtL.begin();
dhtM.begin(); dhtM.begin();
dhtH.begin(); dhtH.begin();
pinMode(BTN_UP, INPUT_PULLDOWN ); pinMode(BTN_UP, INPUT_PULLDOWN);
pinMode(BTN_ENTER, INPUT_PULLDOWN ); pinMode(BTN_ENTER, INPUT_PULLDOWN);
pinMode(BTN_DOWN, INPUT_PULLDOWN ); pinMode(BTN_DOWN, INPUT_PULLDOWN);
rtc.now(); rtc.now();
DateTime now = rtc.now(); DateTime now = rtc.now();
years = now.year(); years = now.year();
@@ -261,86 +276,91 @@ void setup() {
secs = now.second(); secs = now.second();
display.clearDisplay(); display.clearDisplay();
display.setCursor(0,0); display.setCursor(0, 0);
if (!SD.begin(SD_CS)) { if (!SD.begin(SD_CS)) {
display.println("Blad inicjaliz SD!"); display.println("Blad inicjaliz SD!");
display.display(); display.display();
delay(1000); delay(1000);
}else { } else {
Serial.println("Karta SD wykryta!"); Serial.println("Karta SD wykryta!");
} }
display.setCursor(0,16); display.setCursor(0, 16);
if (SD.exists("/TempHumLog.txt")) { if (SD.exists("/TempHumLog.txt")) {
} else { } else {
File file = SD.open("/TempHumLog.txt", FILE_APPEND); File file = SD.open("/TempHumLog.txt", FILE_APPEND);
file.println("Data; Godzina; Temp; Humi; Feel,TempH,HumH, TempM, HumM, TempL, HumL"); file.println("Data; Godzina; Temp; Humi; Feel,TempH,HumH, TempM, HumM, TempL, HumL");
file.close(); file.close();
}
}
sprintf(dateString, "%02d/%02d/%4d %02d:%02d:%02d", now.day(), now.month(), now.year(), now.hour(), now.minute(), now.second()); sprintf(dateString, "%02d/%02d/%4d %02d:%02d:%02d", now.day(), now.month(), now.year(), now.hour(), now.minute(), now.second());
if (SD.exists("/GeneralLog.txt")) { if (SD.exists("/GeneralLog.txt")) {
} else { } else {
File file = SD.open("/GeneralLog.txt", FILE_APPEND);
file.print("Utworzono: ");
file.print(dateString);
file.print(" Wersja: ");
file.println(Version);
file.close();
}
File file = SD.open("/GeneralLog.txt", FILE_APPEND); File file = SD.open("/GeneralLog.txt", FILE_APPEND);
file.print("Uruchomienie: "); file.print("Utworzono: ");
file.print(dateString); file.print(dateString);
file.print(" Wersja: "); file.print(" Wersja: ");
file.println(Version); file.println(Version);
file.close(); file.close();
}
File file = SD.open("/GeneralLog.txt", FILE_APPEND);
file.print("Uruchomienie: ");
file.print(dateString);
file.print(" Wersja: ");
file.println(Version);
file.close();
display.display(); display.display();
delay(500); delay(500);
adcVoltValue = analogRead(VOLT_IN); // Odczyt wartości ADC z GPIO36 adcVoltValue = analogRead(VOLT_IN); // Odczyt wartości ADC z GPIO36
measuredVoltage = (adcVoltValue * adcMaxVoltage) / adcResolution; measuredVoltage = (adcVoltValue * adcMaxVoltage) / adcResolution;
batteryVoltage = (measuredVoltage * voltageDividerFactor)+0.1; batteryVoltage = (measuredVoltage * voltageDividerFactor) + 0.1;
currentBatteryVoltage = batteryVoltage; currentBatteryVoltage = batteryVoltage;
quickBatteryVoltage = batteryVoltage; quickBatteryVoltage = batteryVoltage;
quickBatteryVoltage2 = batteryVoltage; quickBatteryVoltage2 = batteryVoltage;
quickBatteryVoltage3 = batteryVoltage; quickBatteryVoltage3 = batteryVoltage;
quickBatteryVoltage4 = batteryVoltage; quickBatteryVoltage4 = batteryVoltage;
tempH = (dhtH.readTemperature()-0.16); tempH = (dhtH.readTemperature() - 0.16);
lastTempH = tempH; lastTempH = tempH;
tempM = (dhtM.readTemperature()+0.08); tempM = (dhtM.readTemperature() + 0.08);
lastTempM = tempM ; lastTempM = tempM;
tempL = (dhtL.readTemperature()+0.0); tempL = (dhtL.readTemperature() + 0.0);
lastTempL = tempL; lastTempL = tempL;
tempHCalc = ( tempH + lastTempH )/2; tempHCalc = (tempH + lastTempH) / 2;
tempMCalc = ( tempM + lastTempM )/2; tempMCalc = (tempM + lastTempM) / 2;
tempLCalc = ( tempL + lastTempL )/2; tempLCalc = (tempL + lastTempL) / 2;
humHCalc = ( humH + lastHumH )/2; humHCalc = (humH + lastHumH) / 2;
humMCalc = ( humM + lastHumM )/2; humMCalc = (humM + lastHumM) / 2;
humLCalc = ( humL + lastHumL )/2; humLCalc = (humL + lastHumL) / 2;
if (isnan(tempH)) { if (isnan(tempH)) {
lastTempH = 0.0; lastTempH = 0.0;
tempH = lastTempH; } tempH = lastTempH;
}
if (isnan(tempM)) { if (isnan(tempM)) {
lastTempM = 0.0; lastTempM = 0.0;
tempM = lastTempM;} tempM = lastTempM;
}
if (isnan(tempL)) { if (isnan(tempL)) {
lastTempL = 0.0; lastTempL = 0.0;
tempL = lastTempL;} tempL = lastTempL;
}
if (isnan(humH)) { if (isnan(humH)) {
lastHumH = 0.0; lastHumH = 0.0;
humH = lastHumH;} humH = lastHumH;
}
if (isnan(humM)) { if (isnan(humM)) {
lastHumM = 0.0; lastHumM = 0.0;
humM = lastHumM;} humM = lastHumM;
}
if (isnan(humL)) { if (isnan(humL)) {
lastHumL = 0.0; lastHumL = 0.0;
humL = lastHumL;} humL = lastHumL;
}
//setup END //setup END
//###################### //######################
} }
@@ -348,30 +368,41 @@ void setup() {
void loop() { void loop() {
currentMillis = millis(); currentMillis = millis();
display.clearDisplay(); display.clearDisplay();
////DIAGNOSTIC menu nr diag ////DIAGNOSTIC menu nr diag
// display.setCursor(75, 16); // display.setCursor(75, 16);
// display.println(menuL0); // display.println(menuL0);
// display.setCursor(90, 16); // display.setCursor(90, 16);
// display.println(menuL1); // display.println(menuL1);
// display.setCursor(105, 16); // display.setCursor(105, 16);
// display.println(menuL2); // display.println(menuL2);
temp = dht.readTemperature(); temp = dht.readTemperature();
tempH = (dhtH.readTemperature()-0.16); //kalibracja tempH = (dhtH.readTemperature() - 0.16); //kalibracja
if (isnan(tempH)) { tempH = lastTempH;} if (isnan(tempH)) { tempH = lastTempH; }
tempM = (dhtM.readTemperature()+0.08); //kalibracja tempM = (dhtM.readTemperature() + 0.08); //kalibracja
if (isnan(tempM)) { tempM = lastTempM;} if (isnan(tempM)) { tempM = lastTempM; }
tempL = (dhtL.readTemperature()+0.0); tempL = (dhtL.readTemperature() + 0.0);
if (isnan(tempL)) { tempL = lastTempL;} if (isnan(tempL)) { tempL = lastTempL; }
hum = dht.readHumidity(); hum = dht.readHumidity();
humH = (dhtH.readHumidity()+0.0); humH = (dhtH.readHumidity() + 0.0);
if (isnan(humH)) { humH = lastHumH;} if (isnan(humH)) { humH = lastHumH; }
humM = (dhtM.readHumidity()-3.2); //kalibracja humM = (dhtM.readHumidity() - 3.2); //kalibracja
if (isnan(humM)) { humM = lastHumM;} if (isnan(humM)) { humM = lastHumM; }
humL = (dhtL.readHumidity()+1.7); //kalibracja humL = (dhtL.readHumidity() + 1.7); //kalibracja
if (isnan(humL)) { humL = lastHumL;} if (isnan(humL)) { humL = lastHumL; }
//##########################################################################################################################
if (intervalTempIdx = 1) {
intervalTempWrite = 1;
} else if (intervalTempIdx = 2) {
intervalTempWrite = 5;
} else if (intervalTempIdx = 3) {
intervalTempWrite = 15;
} else if (intervalTempIdx = 4) {
intervalTempWrite = 60;
} else {
intervalTempWrite = 360;
}
// Compute heat index in Celsius (isFahreheit = false) // Compute heat index in Celsius (isFahreheit = false)
heat_idx = dht.computeHeatIndex(temp, hum, false); heat_idx = dht.computeHeatIndex(temp, hum, false);
@@ -388,7 +419,7 @@ void loop() {
if (menuL0 == 10 ) { if (menuL0 == 10) {
// ############# MENU TEMP // ############# MENU TEMP
display.setCursor(0, 0); display.setCursor(0, 0);
@@ -407,14 +438,14 @@ void loop() {
display.println("Temperatura:"); display.println("Temperatura:");
display.setCursor(85, 16); display.setCursor(85, 16);
display.println(temp); display.println(temp);
display.setCursor(120,16); display.setCursor(120, 16);
display.println("C"); display.println("C");
display.setCursor(0, 24); display.setCursor(0, 24);
display.println("Odczuwalna:"); display.println("Odczuwalna:");
display.setCursor(85, 24); display.setCursor(85, 24);
display.println(heat_idx); display.println(heat_idx);
display.setCursor(120,24); display.setCursor(120, 24);
display.println("C"); display.println("C");
} }
@@ -428,46 +459,76 @@ void loop() {
if (menuL0 == 9 ) { if (menuL0 == 9) {
if (digitalRead(BTN_ENTER) == HIGH and menuL1 == 10) { if (digitalRead(BTN_ENTER) == HIGH and menuL1 == 10) {
menuL1 = 9; menuL1 = 9;
} }
display.setCursor(0, 0); display.setCursor(0, 0);
sprintf(dateString, "%02d/%02d/%4d %02d:%02d:%02d", now.day(), now.month(), now.year(), now.hour(), now.minute(), now.second()); sprintf(dateString, "%02d/%02d/%4d %02d:%02d:%02d", now.day(), now.month(), now.year(), now.hour(), now.minute(), now.second());
display.println(dateString); display.println(dateString);
if (menuL1 == 10) { if (menuL1 == 10) {
display.setCursor(0, 8); display.setCursor(0, 8);
display.print("Enter edycja czasu"); display.print("Enter edycja czasu");
display.setCursor(0, 16);
display.print("Intwerwal: ");
//##########################################################################################################################
display.print(intervalTempIdx);
if (intervalTempWrite >= 60) {
display.setCursor(60, 16);
display.print((intervalTempIdx / 60));
display.setCursor(80, 16);
display.print("godz");
} else {
display.setCursor(60, 16);
display.print((intervalTempIdx));
display.setCursor(80, 16);
display.print("godz");
}
} }
if (menuL1 == 9) { if (menuL1 == 9) {
display.setCursor(0, 8); display.setCursor(0, 8);
delay(100); delay(100);
display.print("Ustaw godziny"); display.print("Interwal:");
delay(150); delay(100);
if (digitalRead(BTN_ENTER) == HIGH and menuL2 == 10) { if (digitalRead(BTN_ENTER) == HIGH and menuL2 == 10) {
menuL2 = 9; menuL2 = 9;
} }
//##########################################################################################################################
if (menuL2 == 9) {
display.setCursor(0, 16);
display.print("Ustaw godziny");
display.setCursor(45, 16);
display.print(hoursToSet);
delay(100);
if (menuL2 == 9){ if (digitalRead(BTN_ENTER) == HIGH) {
display.setCursor(0,16); intervalTempWrite++;
display.print("Godzina:"); if (intervalTempWrite >= 6) {
display.setCursor(45,16); intervalTempWrite = 1;
if (hoursToSet == -1){ }
hoursToSet = now.hour(); }
} }
display.print(hoursToSet); if (menuL2 == 8) {
delay(100); display.setCursor(0, 16);
display.print("Godzina:");
display.setCursor(45, 16);
if (hoursToSet == -1) {
hoursToSet = now.hour();
}
display.print(hoursToSet);
delay(100);
if (digitalRead(BTN_ENTER) == HIGH) { if (digitalRead(BTN_ENTER) == HIGH) {
// tu ustawianie czasu // tu ustawianie czasu
menuL2 = 10; menuL2 = 10;
rtc.adjust(DateTime(now.year(), now.month(), now.day(), hoursToSet, now.minute(), now.second())); rtc.adjust(DateTime(now.year(), now.month(), now.day(), hoursToSet, now.minute(), now.second()));
hoursToSet = -1; hoursToSet = -1;
} }
} }
} }
if (menuL1 == 8) { if (menuL1 == 7) {
display.setCursor(0, 8); display.setCursor(0, 8);
display.print("Ustaw minuty"); display.print("Ustaw minuty");
@@ -475,54 +536,54 @@ void loop() {
menuL2 = 9; menuL2 = 9;
} }
if (menuL2 == 9){ if (menuL2 == 9) {
display.setCursor(0,16); display.setCursor(0, 16);
display.print("Minuta:"); display.print("Minuta:");
display.setCursor(45,16); display.setCursor(45, 16);
if (minsToSet == -1){ if (minsToSet == -1) {
minsToSet = now.minute(); minsToSet = now.minute();
} }
display.print(minsToSet); display.print(minsToSet);
delay(250); delay(250);
if (digitalRead(BTN_ENTER) == HIGH) { if (digitalRead(BTN_ENTER) == HIGH) {
// tu ustawianie czasu // tu ustawianie czasu
menuL2 = 10; menuL2 = 10;
rtc.adjust(DateTime(now.year(), now.month(), now.day(), now.hour(), minsToSet, now.second())); rtc.adjust(DateTime(now.year(), now.month(), now.day(), now.hour(), minsToSet, now.second()));
minsToSet = -1; minsToSet = -1;
} }
} }
if (menuL2 == 6){ if (menuL2 == 6) {
display.setCursor(0,24); display.setCursor(0, 24);
display.print("Wyjdz"); display.print("Wyjdz");
if (digitalRead(BTN_ENTER) == HIGH) { if (digitalRead(BTN_ENTER) == HIGH) {
menuL2 = 10; menuL2 = 10;
} }
} }
} }
if (menuL1 == 7 ) { if (menuL1 == 36) {
display.setCursor(0, 8); display.setCursor(0, 8);
display.print("Ustaw sekundy na 0"); display.print("Ustaw sekundy na 0");
if (digitalRead(BTN_ENTER) == HIGH and menuL2 == 10) { if (digitalRead(BTN_ENTER) == HIGH and menuL2 == 10) {
menuL2 = 9; menuL2 = 9;
} }
if (menuL2 == 9){ if (menuL2 == 9) {
display.setCursor(0,16); display.setCursor(0, 16);
display.print("Sekundy = 0"); display.print("Sekundy = 0");
delay(250); delay(250);
if (digitalRead(BTN_ENTER) == HIGH) { if (digitalRead(BTN_ENTER) == HIGH) {
menuL2 = 10; menuL2 = 10;
rtc.adjust(DateTime(now.year(), now.month(), now.day(), now.hour(), now.minute(),0)); rtc.adjust(DateTime(now.year(), now.month(), now.day(), now.hour(), now.minute(), 0));
minsToSet = -1; minsToSet = -1;
} }
} }
} }
if (menuL1 == 6) { if (menuL1 == 6) {
display.setCursor(0, 8); display.setCursor(0, 8);
display.print("Wyjdz"); display.print("Wyjdz");
if (digitalRead(BTN_ENTER) == HIGH) { if (digitalRead(BTN_ENTER) == HIGH) {
@@ -532,7 +593,7 @@ void loop() {
} }
if (menuL0 == 8 ) { if (menuL0 == 8) {
display.setCursor(0, 0); display.setCursor(0, 0);
display.println(dateString); display.println(dateString);
display.setCursor(0, 8); display.setCursor(0, 8);
@@ -541,56 +602,56 @@ void loop() {
display.print(batteryPercent); display.print(batteryPercent);
display.setCursor(70, 8); display.setCursor(70, 8);
display.print("%"); display.print("%");
display.setCursor(80,8); display.setCursor(80, 8);
display.print("V:"); display.print("V:");
display.setCursor(95, 8); display.setCursor(95, 8);
display.print(batteryVoltage); display.print(batteryVoltage);
display.setCursor(0, 24); display.setCursor(0, 24);
if (currentBatteryVoltage >= 4.20 ){ if (currentBatteryVoltage >= 4.20) {
display.print("Full"); display.print("Full");
chrgState = "FUL"; chrgState = "FUL";
} else if ((lastBatteryVoltage < currentBatteryVoltage && currentBatteryVoltage >= 2.0&& currentBatteryVoltage >= 4.0 ) || currentBatteryVoltage >= 4.10 ){ } else if ((lastBatteryVoltage < currentBatteryVoltage && currentBatteryVoltage >= 2.0 && currentBatteryVoltage >= 4.0) || currentBatteryVoltage >= 4.10) {
display.print("Charging"); display.print("Charging");
chrgState = "CHR"; chrgState = "CHR";
} else if (lastBatteryVoltage >=currentBatteryVoltage && currentBatteryVoltage >= 2.0 ) { } else if (lastBatteryVoltage >= currentBatteryVoltage && currentBatteryVoltage >= 2.0) {
display.print("Discharge"); display.print("Discharge");
chrgState = "DSG"; chrgState = "DSG";
} else { } else {
display.print("xxx"); display.print("xxx");
chrgState = "xxx"; chrgState = "xxx";
} }
if (chrgState == "CHR") { if (chrgState == "CHR") {
batteryPercent = chargeVoltageToPercentage(currentBatteryVoltage); batteryPercent = chargeVoltageToPercentage(currentBatteryVoltage);
} else { } else {
batteryPercent = voltageToPercentage(currentBatteryVoltage); batteryPercent = voltageToPercentage(currentBatteryVoltage);
} }
display.setCursor(60, 24); display.setCursor(60, 24);
display.print("Est:"); display.print("Est:");
estHours = int(floor( ((float(batteryPercent)/100) * battLifeMins) /60) ); estHours = int(floor(((float(batteryPercent) / 100) * battLifeMins) / 60));
display.setCursor(85, 24); display.setCursor(85, 24);
display.print(leadZero(estHours)); display.print(leadZero(estHours));
display.setCursor(99, 24); display.setCursor(99, 24);
display.print("h"); display.print("h");
estMins = ((float(batteryPercent)/100) * battLifeMins) - (estHours * 60); estMins = ((float(batteryPercent) / 100) * battLifeMins) - (estHours * 60);
display.setCursor(107, 24); display.setCursor(107, 24);
display.print(leadZero(estMins)); display.print(leadZero(estMins));
display.setCursor(120, 24); display.setCursor(120, 24);
display.print("m"); display.print("m");
display.drawRect(0,16, 124, 7, SSD1306_WHITE); display.drawRect(0, 16, 124, 7, SSD1306_WHITE);
display.fillRect(124, 17, 5, 5, SSD1306_WHITE); display.fillRect(124, 17, 5, 5, SSD1306_WHITE);
batteryBarWidth = int(((float(batteryPercent)/100)*122)); batteryBarWidth = int(((float(batteryPercent) / 100) * 122));
if (batteryBarWidth >122){ if (batteryBarWidth > 122) {
batteryBarWidth = 122; batteryBarWidth = 122;
} }
display.fillRect(1, 17, batteryBarWidth, 6, SSD1306_WHITE); display.fillRect(1, 17, batteryBarWidth, 6, SSD1306_WHITE);
if (batteryVoltage < 2 ){ if (batteryVoltage < 2) {
display.setCursor(60,15 ); display.setCursor(60, 15);
display.print("xxx"); display.print("xxx");
} }
if (digitalRead(BTN_UP) == HIGH) { if (digitalRead(BTN_UP) == HIGH) {
@@ -606,177 +667,171 @@ void loop() {
display.print("DOWN"); display.print("DOWN");
} }
} }
if (menuL0 == 7 ) { if (menuL0 == 7) {
display.setCursor(0, 0); display.setCursor(0, 0);
display.println(dateString); display.println(dateString);
display.setCursor(0, 8); display.setCursor(0, 8);
display.println("TemH"); display.println("TemH");
display.setCursor(30, 8); display.setCursor(30, 8);
display.println(tempH,1); display.println(tempH, 1);
display.setCursor(55, 8); display.setCursor(55, 8);
display.println("C"); display.println("C");
display.setCursor(65, 8); display.setCursor(65, 8);
display.println("HumH"); display.println("HumH");
display.setCursor(95, 8); display.setCursor(95, 8);
display.println(humH,1); display.println(humH, 1);
display.setCursor(120,8); display.setCursor(120, 8);
display.println("%"); display.println("%");
display.setCursor(0, 16); display.setCursor(0, 16);
display.println("TemM"); display.println("TemM");
display.setCursor(30, 16); display.setCursor(30, 16);
display.println(tempM,1); display.println(tempM, 1);
display.setCursor(55, 16); display.setCursor(55, 16);
display.println("C"); display.println("C");
display.setCursor(65, 16); display.setCursor(65, 16);
display.println("HumM"); display.println("HumM");
display.setCursor(95, 16); display.setCursor(95, 16);
display.println(humM,1); display.println(humM, 1);
display.setCursor(120,16); display.setCursor(120, 16);
display.println("%"); display.println("%");
display.setCursor(0, 24); display.setCursor(0, 24);
display.println("TemL"); display.println("TemL");
display.setCursor(30, 24); display.setCursor(30, 24);
display.println(tempL,1); display.println(tempL, 1);
display.setCursor(55, 24); display.setCursor(55, 24);
display.println("C"); display.println("C");
display.setCursor(65, 24); display.setCursor(65, 24);
display.println("HumL"); display.println("HumL");
display.setCursor(95, 24); display.setCursor(95, 24);
display.println(humL,1); display.println(humL, 1);
display.setCursor(120,24); display.setCursor(120, 24);
display.println("%"); display.println("%");
} }
if (digitalRead(BTN_UP) == HIGH and menuL0 <10 ) { if (digitalRead(BTN_UP) == HIGH and menuL0 < 10) {
if ( menuL0 < 10 && menuL1 == 10 ) { if (menuL0 < 10 && menuL1 == 10) {
menuL0 = menuL0 + 1; menuL0 = menuL0 + 1;
}
if (menuL1 < 9 && menuL2 == 10) {
menuL1 = menuL1 + 1;
}
if (menuL2 < 9 and menuL0 != 10 and menuL1 != 10) {
menuL2 = menuL2 + 1;
}
if (menuL2 == 9 and minsToSet <59)
{
minsToSet = minsToSet + 1;
}
if (menuL2 == 9 and hoursToSet < 23)
{
hoursToSet = hoursToSet + 1;
}
} }
if (menuL1 < 9 && menuL2 == 10) {
if (digitalRead(BTN_DOWN) == HIGH and menuL0 >= 7) { menuL1 = menuL1 + 1;
if (menuL0 > 7 && menuL1 == 10 ) {
menuL0 = menuL0 - 1;
}
if (menuL1 > 6 and menuL1 <= 9 && menuL2 == 10) {
menuL1 = menuL1 - 1;
}
if (menuL2 > 6 and menuL2 < 9 and menuL0 != 10 and menuL1 != 10 ) {
menuL2 = menuL2 - 1;
}
if (menuL2 == 9 and minsToSet > 1)
{
minsToSet = minsToSet - 1;
}
if (menuL2 == 9 and hoursToSet > 1)
{
hoursToSet = hoursToSet - 1;
}
} }
if (menuL2 < 9 and menuL0 != 10 and menuL1 != 10) {
menuL2 = menuL2 + 1;
}
if (menuL2 == 9 and minsToSet < 59) {
minsToSet = minsToSet + 1;
}
if (menuL2 == 9 and hoursToSet < 23) {
hoursToSet = hoursToSet + 1;
}
}
if (digitalRead(BTN_DOWN) == HIGH and menuL0 >= 7) {
if (menuL0 > 7 && menuL1 == 10) {
menuL0 = menuL0 - 1;
}
if (menuL1 > 6 and menuL1 <= 9 && menuL2 == 10) {
menuL1 = menuL1 - 1;
}
if (menuL2 > 6 and menuL2 < 9 and menuL0 != 10 and menuL1 != 10) {
menuL2 = menuL2 - 1;
}
if (menuL2 == 9 and minsToSet > 1) {
minsToSet = minsToSet - 1;
}
if (menuL2 == 9 and hoursToSet > 1) {
hoursToSet = hoursToSet - 1;
}
}
if (currentMillis - previousMillis >= interval) { if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis; previousMillis = currentMillis;
adcVoltValue = analogRead(VOLT_IN); // Odczyt wartości ADC z GPIO36 adcVoltValue = analogRead(VOLT_IN); // Odczyt wartości ADC z GPIO36
measuredVoltage = (adcVoltValue * adcMaxVoltage) / adcResolution; measuredVoltage = (adcVoltValue * adcMaxVoltage) / adcResolution;
quickBatteryVoltage4 = quickBatteryVoltage3; quickBatteryVoltage4 = quickBatteryVoltage3;
quickBatteryVoltage3 = quickBatteryVoltage2; quickBatteryVoltage3 = quickBatteryVoltage2;
quickBatteryVoltage2 = quickBatteryVoltage; quickBatteryVoltage2 = quickBatteryVoltage;
quickBatteryVoltage = (measuredVoltage * voltageDividerFactor)+0.1; quickBatteryVoltage = (measuredVoltage * voltageDividerFactor) + 0.1;
batteryVoltage = (quickBatteryVoltage + quickBatteryVoltage2 + quickBatteryVoltage3 + quickBatteryVoltage4)/4; batteryVoltage = (quickBatteryVoltage + quickBatteryVoltage2 + quickBatteryVoltage3 + quickBatteryVoltage4) / 4;
} }
// Log napiećia docelowoe procent baterii // Log napiećia docelowoe procent baterii
// kiedy zaden przycisk nie jest wcisniety // kiedy zaden przycisk nie jest wcisniety
if (abs (batteryVoltage - currentBatteryVoltage) >= 0.14 && digitalRead(BTN_DOWN) == LOW && digitalRead(BTN_UP) == LOW && digitalRead(BTN_ENTER) == LOW ) { if (abs(batteryVoltage - currentBatteryVoltage) >= 0.14 && digitalRead(BTN_DOWN) == LOW && digitalRead(BTN_UP) == LOW && digitalRead(BTN_ENTER) == LOW) {
lastBatteryVoltage = currentBatteryVoltage; lastBatteryVoltage = currentBatteryVoltage;
currentBatteryVoltage = batteryVoltage; currentBatteryVoltage = batteryVoltage;
} }
if (secs % 15 == 0) { if (secs % 15 == 0) {
lastBatteryVoltage = currentBatteryVoltage; lastBatteryVoltage = currentBatteryVoltage;
currentBatteryVoltage = batteryVoltage; currentBatteryVoltage = batteryVoltage;
delay(500); delay(500);
}
}
//zapis na SD poziom baterii //zapis na SD poziom baterii
if (mins % 1 == 0 && secs == 0) { if (mins % 1 == 0 && secs == 0) {
File file = SD.open("/GeneralLog.txt", FILE_APPEND); File file = SD.open("/GeneralLog.txt", FILE_APPEND);
if (file) { if (file) {
display.fillRect(0, 0, 128, 64, SSD1306_WHITE); display.fillRect(0, 0, 128, 64, SSD1306_WHITE);
file.print(dateString); file.print(dateString);
file.print(" Battery %: "); file.print(" Battery %: ");
file.print(batteryPercent); file.print(batteryPercent);
file.print(" V: "); file.print(" V: ");
file.println(formatNumber(currentBatteryVoltage,2)); file.println(formatNumber(currentBatteryVoltage, 2));
file.close(); file.close();
} }
} }
//zapis na SD temp i hum //zapis na SD temp i hum
if (mins % intervalTempWrite == 0 && secs == 0) { if (mins % intervalTempWrite == 0 && secs == 0) {
File file = SD.open("/TempHumLog.txt", FILE_APPEND); File file = SD.open("/TempHumLog.txt", FILE_APPEND);
if (file) { if (file) {
display.fillRect(0, 0, 124, 64, SSD1306_WHITE); display.fillRect(0, 0, 124, 64, SSD1306_WHITE);
tempHCalc = ( tempH + lastTempH )/2; tempHCalc = (tempH + lastTempH) / 2;
tempMCalc = ( tempM + lastTempM )/2; tempMCalc = (tempM + lastTempM) / 2;
tempLCalc = ( tempL + lastTempL )/2; tempLCalc = (tempL + lastTempL) / 2;
humHCalc = ( humH + lastHumH )/2; humHCalc = (humH + lastHumH) / 2;
humMCalc = ( humM + lastHumM )/2; humMCalc = (humM + lastHumM) / 2;
humLCalc = ( humL + lastHumL )/2; humLCalc = (humL + lastHumL) / 2;
lastTempH = tempH; lastTempH = tempH;
lastTempM = tempM; lastTempM = tempM;
lastTempL = tempL; lastTempL = tempL;
lastHumH = humH; lastHumH = humH;
lastHumM = humM; lastHumM = humM;
lastHumL = humL; lastHumL = humL;
file.print(leadZero(dayss)); file.print(leadZero(dayss));
file.print("/"); file.print("/");
file.print(leadZero(months)); file.print(leadZero(months));
file.print("/"); file.print("/");
file.print(years); file.print(years);
file.print("; "); file.print("; ");
file.print(leadZero(hourss)); file.print(leadZero(hourss));
file.print(":"); file.print(":");
file.print(leadZero(mins)); file.print(leadZero(mins));
file.print("; "); file.print("; ");
file.print(formatNumber(temp)); file.print(formatNumber(temp));
file.print("; "); file.print("; ");
file.print(formatNumber(hum)); file.print(formatNumber(hum));
file.print("; "); file.print("; ");
file.print(formatNumber(heat_idx)); file.print(formatNumber(heat_idx));
file.print("; "); file.print("; ");
file.print(formatNumber(tempHCalc)); file.print(formatNumber(tempHCalc));
file.print("; "); file.print("; ");
file.print(formatNumber(humHCalc)); file.print(formatNumber(humHCalc));
file.print("; "); file.print("; ");
file.print(formatNumber(tempMCalc)); file.print(formatNumber(tempMCalc));
file.print("; "); file.print("; ");
file.print(formatNumber(humMCalc)); file.print(formatNumber(humMCalc));
file.print("; "); file.print("; ");
file.print(formatNumber(tempLCalc)); file.print(formatNumber(tempLCalc));
file.print("; "); file.print("; ");
file.println(formatNumber(humLCalc)); file.println(formatNumber(humLCalc));
file.close(); file.close();
delay(1000); delay(1000);
} }
} }
display.display(); display.display();
delay(150); delay(150);
yield(); yield();