From d34008397724d455525cdf895fd52f8c2459a89c Mon Sep 17 00:00:00 2001 From: sieja Date: Sun, 15 Jun 2025 18:17:18 +0200 Subject: [PATCH] =?UTF-8?q?Poprawa=20wyliczania=20speedTrend=20Porz=C4=85d?= =?UTF-8?q?ki?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ESP_AutomatedGearShifter.ino | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/ESP32/ESP_AutomatedGearShifter/ESP_AutomatedGearShifter.ino b/ESP32/ESP_AutomatedGearShifter/ESP_AutomatedGearShifter.ino index 7d33abf..22532de 100644 --- a/ESP32/ESP_AutomatedGearShifter/ESP_AutomatedGearShifter.ino +++ b/ESP32/ESP_AutomatedGearShifter/ESP_AutomatedGearShifter.ino @@ -5,7 +5,7 @@ #include #include -#define Version "2.2.0" +#define Version "2.2.3" ////2DO: // menu do zmiany zakresu predkosci biegów // 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; double calcTimeDiff = 0.0; double lastGearCalc = millis(); -double changeDelayMs = 1000.0; +double speedDiff = 1.0; double accelerationShift = 1.0; int displGear = 9 - currentGear; float currentGearRangeLower = 0; @@ -83,10 +83,8 @@ float currentGearRangeUpper = 7.5; int pos = 0; int sleepMode = 0; int servoCurrPos = ServoMaxAngle; -//GearBar -int gearBarHeight = 0; -int gearBarPosition = 0; -float speedForBar = 0; +//GearRangePointer +int pointerPosition = 0; unsigned int pointerVisibility = 1; //BATTERY float referenceVoltage = 3.3; @@ -263,7 +261,7 @@ void calcSpeed(){ calcSpeedAvg = (calcSpeed1 + calcSpeed2 + calcSpeed3)/3; calcSpeedMain = calcSpeedAvg; - if(abs(raw_speed - calcSpeed2) >= changeDelayMs) { + if(abs(raw_speed - calcSpeed2) >= speedDiff) { if ((raw_speed - calcSpeed2) < 0) { speedTrend = -1; @@ -314,9 +312,14 @@ void calcGear() { }; calcTimeDiff = millis() - lastGearCalc; - if (calcTimeDiff < 2000 && abs((calculatedGear-currentGear))<=1){ + if (calcTimeDiff < 2000 && abs((calculatedGear-currentGear)) <= 1){ currentGear = currentGear; - pointerVisibility = 0; + if (abs((calculatedGear-currentGear)) > 0){ + pointerVisibility = 0; + + }else { + pointerVisibility = 1; + } } else { currentGear = calculatedGear; lastGearCalc = millis(); @@ -386,14 +389,14 @@ void loop() { display.println("S:"); display.setCursor(40, 40); display.println(calcSpeedMain, 1); - //GearBar - if (pointerVisibility = 1){ + //GearRangePointer + if (pointerVisibility == 1){ display.fillRect(115, 32, 7, 1, SSD1306_WHITE); display.fillRect(115, 0, 7, 1, SSD1306_WHITE); display.fillRect(115, 63, 7, 1, SSD1306_WHITE); display.setTextSize(2); - gearBarHeight = 64 - int(((calcSpeedMain - currentGearRangeLower) / (currentGearRangeUpper - currentGearRangeLower)) * 64) - 5; - display.setCursor(115, gearBarHeight); + pointerPosition = 64 - int(((calcSpeedMain - currentGearRangeLower) / (currentGearRangeUpper - currentGearRangeLower)) * 64) - 5; + display.setCursor(115, pointerPosition); display.write(16); display.setTextSize(3); }