Compare commits

..

2 Commits

Author SHA1 Message Date
sieja
23421392c7 Korekta 2025-06-21 12:35:10 +02:00
sieja
f2c1747a44 Dodawnie zmiany interwalu 2025-06-19 11:58:57 +02:00
2 changed files with 111 additions and 49 deletions

View File

@@ -5,7 +5,7 @@
#include <Adafruit_GFX.h> #include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h> #include <Adafruit_SSD1306.h>
#define Version "2.2.4" #define Version "2.2.5"
////2DO: ////2DO:
// menu do zmiany zakresu predkosci biegów // menu do zmiany zakresu predkosci biegów
// menu do zmiany zakresu kątów biegów, obwodu koła, ilosci magnesow // menu do zmiany zakresu kątów biegów, obwodu koła, ilosci magnesow
@@ -74,7 +74,7 @@ float spdRange6and7 = 29.9;
float spdRange7and8 = 36.5; float spdRange7and8 = 36.5;
double calcTimeDiff = 0.0; double calcTimeDiff = 0.0;
double lastGearCalc = millis(); double lastGearCalc = millis();
double speedDiff = 0.65; double speedDiff = 0.7;
double accelerationShift = 1.0; double accelerationShift = 1.0;
int displGear = 9 - currentGear; int displGear = 9 - currentGear;
float currentGearRangeLower = 0; float currentGearRangeLower = 0;
@@ -264,11 +264,6 @@ void calcSpeed(){
if(abs(raw_speed - calcSpeed2) >= speedDiff) { if(abs(raw_speed - calcSpeed2) >= speedDiff) {
if ((raw_speed - calcSpeed2) < 0) { if ((raw_speed - calcSpeed2) < 0) {
speedTrend = -1; speedTrend = -1;
readSignalTime_1 = -1;
readSignalTime_2 = -1;
readSignalTime_3 = -1;
readSignalTimeAvg = -1;
} else { } else {
speedTrend = 1; speedTrend = 1;
} }
@@ -319,7 +314,6 @@ void calcGear() {
if (calcTimeDiff < 1500 && (calculatedGear - currentGear) == 1){ if (calcTimeDiff < 1500 && (calculatedGear - currentGear) == 1){
currentGear = calculatedGear; currentGear = calculatedGear;
pointerVisibility = 0; pointerVisibility = 0;
} else { } else {
currentGear = calculatedGear; currentGear = calculatedGear;
lastGearCalc = millis(); lastGearCalc = millis();
@@ -355,6 +349,9 @@ void loop() {
sleepSpd = millis() - millissSpd; sleepSpd = millis() - millissSpd;
if (sleepSpd >= 1000.0) { //podaj zerową prędkość jeśli nie było odcztu od 1,1 s if (sleepSpd >= 1000.0) { //podaj zerową prędkość jeśli nie było odcztu od 1,1 s
raw_speed = 0.0; raw_speed = 0.0;
calcSpeed3 = 0.0;
calcSpeed2 = 0.0;
calcSpeed1 = 0.0;
} }
//przejście w tryb uśpienia za przuycisku lub czasu //przejście w tryb uśpienia za przuycisku lub czasu
if ((digitalRead(Btn2) == HIGH)|| (sleepSpd >= LongTimeToSleep)) { if ((digitalRead(Btn2) == HIGH)|| (sleepSpd >= LongTimeToSleep)) {

View File

@@ -10,7 +10,7 @@
#include "SD.h" #include "SD.h"
#include "SPI.h" #include "SPI.h"
#define Version "0.47" #define Version "0.48"
#define WIRE Wire #define WIRE Wire
#define DHTTYPE DHT22 #define DHTTYPE DHT22
#define DHTPIN 4 //GPIO04 D4 #define DHTPIN 4 //GPIO04 D4
@@ -84,10 +84,13 @@ int years;
//########################################################################################################################## //##########################################################################################################################
int intervalTempIdx = 3; int intervalTempIdx = 3;
int intervalTempWrite = 0; int intervalTempWrite = 0;
int intervalTempWriteMins = 0;
int intervalTempWriteHours = 0;
int minsToSet = -1; int minsToSet = -1;
int hoursToSet = -1; int hoursToSet = -1;
int intervalToSet = -1;
int adcVoltValue; int adcVoltValue;
float measuredVoltage = 0; float measuredVoltage = 0;
@@ -230,13 +233,13 @@ 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) { if (intervalTempIdx == 1) {
intervalTempWrite = 1; intervalTempWrite = 1;
} else if (intervalTempIdx = 2) { } else if (intervalTempIdx == 2) {
intervalTempWrite = 5; intervalTempWrite = 5;
} else if (intervalTempIdx = 3) { } else if (intervalTempIdx == 3) {
intervalTempWrite = 15; intervalTempWrite = 15;
} else if (intervalTempIdx = 4) { } else if (intervalTempIdx == 4) {
intervalTempWrite = 60; intervalTempWrite = 60;
} else { } else {
intervalTempWrite = 360; intervalTempWrite = 360;
@@ -362,7 +365,7 @@ void setup() {
humL = lastHumL; humL = lastHumL;
} }
//setup END //setup END
//###################### //######################################################################################################################################################################
} }
void loop() { void loop() {
@@ -391,14 +394,13 @@ void loop() {
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) {
if (intervalTempIdx = 1) {
intervalTempWrite = 1; intervalTempWrite = 1;
} else if (intervalTempIdx = 2) { } else if (intervalTempIdx == 2) {
intervalTempWrite = 5; intervalTempWrite = 5;
} else if (intervalTempIdx = 3) { } else if (intervalTempIdx == 3) {
intervalTempWrite = 15; intervalTempWrite = 15;
} else if (intervalTempIdx = 4) { } else if (intervalTempIdx == 4) {
intervalTempWrite = 60; intervalTempWrite = 60;
} else { } else {
intervalTempWrite = 360; intervalTempWrite = 360;
@@ -469,56 +471,101 @@ void loop() {
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.setCursor(0, 18);
display.print("Intwerwal: "); display.print("Inwerwal: ");
//########################################################################################################################## //##########################################################################################################################
display.print(intervalTempIdx);
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;
}
if (intervalTempWrite >= 60) { if (intervalTempWrite >= 60) {
display.setCursor(60, 16); display.setCursor(60, 18);
display.print((intervalTempIdx / 60)); display.print((intervalTempWrite / 60));
display.setCursor(80, 16); display.setCursor(80, 18);
display.print("godz"); display.print("godz");
} else { } else {
display.setCursor(60, 16); display.setCursor(60, 18);
display.print((intervalTempIdx)); display.print((intervalTempWrite));
display.setCursor(80, 16); display.setCursor(80, 18);
display.print("godz"); display.print("min");
} }
} }
if (menuL1 == 9) { if (menuL1 == 9) {
display.setCursor(0, 8); display.setCursor(0, 8);
delay(100); delay(100);
display.print("Interwal:"); display.print("Ustaw Interwal");
delay(100); 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) { if (menuL2 == 9) {
display.setCursor(0, 16); display.setCursor(0, 16);
display.print("Ustaw godziny"); display.print("Interwal:");
display.setCursor(45, 16); display.setCursor(64, 16);
display.print(hoursToSet); if (intervalToSet == -1) {
delay(100); intervalToSet = intervalTempIdx;
}
if (intervalToSet == 1) {
intervalTempWrite = 1;
} else if (intervalToSet == 2) {
intervalTempWrite = 5;
} else if (intervalToSet == 3) {
intervalTempWrite = 15;
} else if (intervalToSet == 4) {
intervalTempWrite = 60;
} else {
intervalTempWrite = 360;
}
if (intervalTempWrite >= 60) {
display.setCursor(60, 16);
display.print((intervalTempWrite / 60));
display.setCursor(80, 16);
display.print("godz");
} else {
display.setCursor(60, 16);
display.print((intervalTempWrite));
display.setCursor(80, 16);
display.print("min");
}
delay(250);
if (digitalRead(BTN_ENTER) == HIGH) { if (digitalRead(BTN_ENTER) == HIGH) {
intervalTempWrite++; menuL2 = 10;
if (intervalTempWrite >= 6) { intervalTempIdx = intervalToSet;
intervalTempWrite = 1; intervalToSet = -1;
}
} }
} }
if (menuL2 == 8) {
}
if (menuL1 == 8) {
display.setCursor(0, 8);
display.print("Ustaw godziny");
if (digitalRead(BTN_ENTER) == HIGH and menuL2 == 10) {
menuL2 = 9;
}
if (menuL2 == 9) {
display.setCursor(0, 16); display.setCursor(0, 16);
display.print("Godzina:"); display.print("Godzina:");
display.setCursor(45, 16); display.setCursor(50, 16);
if (hoursToSet == -1) { if (hoursToSet == -1) {
hoursToSet = now.hour(); hoursToSet = now.hour();
} }
display.print(hoursToSet); display.print(hoursToSet);
delay(100); delay(250);
if (digitalRead(BTN_ENTER) == HIGH) { if (digitalRead(BTN_ENTER) == HIGH) {
// tu ustawianie czasu // tu ustawianie czasu
@@ -528,6 +575,8 @@ void loop() {
} }
} }
} }
if (menuL1 == 7) { if (menuL1 == 7) {
display.setCursor(0, 8); display.setCursor(0, 8);
display.print("Ustaw minuty"); display.print("Ustaw minuty");
@@ -562,7 +611,7 @@ void loop() {
} }
} }
} }
if (menuL1 == 36) { if (menuL1 == 6) {
display.setCursor(0, 8); display.setCursor(0, 8);
display.print("Ustaw sekundy na 0"); display.print("Ustaw sekundy na 0");
@@ -583,7 +632,7 @@ void loop() {
} }
} }
if (menuL1 == 6) { if (menuL1 == 5) {
display.setCursor(0, 8); display.setCursor(0, 8);
display.print("Wyjdz"); display.print("Wyjdz");
if (digitalRead(BTN_ENTER) == HIGH) { if (digitalRead(BTN_ENTER) == HIGH) {
@@ -726,13 +775,16 @@ void loop() {
if (menuL2 == 9 and hoursToSet < 23) { if (menuL2 == 9 and hoursToSet < 23) {
hoursToSet = hoursToSet + 1; hoursToSet = hoursToSet + 1;
} }
if (menuL2 == 9 and intervalToSet < 5) {
intervalToSet = intervalToSet + 1;
}
} }
if (digitalRead(BTN_DOWN) == HIGH and menuL0 >= 7) { if (digitalRead(BTN_DOWN) == HIGH and menuL0 >= 7) {
if (menuL0 > 7 && menuL1 == 10) { if (menuL0 > 7 && menuL1 == 10) {
menuL0 = menuL0 - 1; menuL0 = menuL0 - 1;
} }
if (menuL1 > 6 and menuL1 <= 9 && menuL2 == 10) { if (menuL1 > 5 and menuL1 <= 9 && menuL2 == 10) {
menuL1 = menuL1 - 1; menuL1 = menuL1 - 1;
} }
if (menuL2 > 6 and menuL2 < 9 and menuL0 != 10 and menuL1 != 10) { if (menuL2 > 6 and menuL2 < 9 and menuL0 != 10 and menuL1 != 10) {
@@ -744,6 +796,9 @@ void loop() {
if (menuL2 == 9 and hoursToSet > 1) { if (menuL2 == 9 and hoursToSet > 1) {
hoursToSet = hoursToSet - 1; hoursToSet = hoursToSet - 1;
} }
if (menuL2 == 9 and intervalToSet > 1) {
intervalToSet = intervalToSet - 1;
}
} }
@@ -771,7 +826,7 @@ void loop() {
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 == 7) {
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);
@@ -783,9 +838,19 @@ void loop() {
file.close(); file.close();
} }
} }
Serial.println("intervalTempWrite");
Serial.println(intervalTempWrite);
Serial.println("dzielenie");
Serial.println(mins % intervalTempWrite);
//zapis na SD temp i hum //zapis na SD temp i hum
if (mins % intervalTempWrite == 0 && secs == 0) { if (intervalTempWrite >=360){
intervalTempWriteHours = (intervalTempWrite/60);
} else {
intervalTempWriteHours = -1;
}
if ((intervalTempWriteHours == -1 && mins % intervalTempWrite == 0) or (intervalTempWriteHours == hourss && mins == 0) && secs == 0){
// 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);