From 6627f545fe20228263b0450f54b12099fe7fb6d4 Mon Sep 17 00:00:00 2001 From: Kamil Siejka Date: Tue, 22 Oct 2024 20:57:37 +0200 Subject: [PATCH] =?UTF-8?q?1.14.0=20dodanie=204magnes=C3=B3w=20-=208=20ttl?= =?UTF-8?q?=20bugfix=20liczenia=20odleg=C5=82osci=20z=20odczytu=20magnesu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AutomatedGearShifter/AutomatedGearShifter.ino | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/LeonardoProMicro/AutomatedGearShifter/AutomatedGearShifter.ino b/LeonardoProMicro/AutomatedGearShifter/AutomatedGearShifter.ino index 4a58775..7dedd05 100644 --- a/LeonardoProMicro/AutomatedGearShifter/AutomatedGearShifter.ino +++ b/LeonardoProMicro/AutomatedGearShifter/AutomatedGearShifter.ino @@ -1,4 +1,3 @@ - #include #include // model servo: DS3218 PRO #include @@ -7,7 +6,7 @@ #include #include -#define Version "1.13.19" +#define Version "1.14.0" ////2DO: //pomiar napięcia na baterii // menu do zmiany zakresu predkosci biegów @@ -33,7 +32,7 @@ Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); #define MaxGear 8 #define MinGear 1 #define WheelCircumference 2.130 -#define MagnetsCnt 4 +#define MagnetsCnt 8 #define ms2kmh 3.6 #define Pi 3.1416 #define TimeToSleep 5000 //5 sec @@ -90,7 +89,7 @@ int run_mins = 0; //DST int totalDistMemLocation = 60; int loop_cnt = 0; -unsigned int totalDist = 0; +double totalDist = 0.0; unsigned int totalDistReaded = 0; unsigned int totalDistWrited = 0; //BATTERY @@ -281,9 +280,9 @@ void loop() { //TTL DST // totalDist = 0; loop_cnt = loop_cnt +1; - if (loop_cnt >= 10 && totalDistWrited != totalDist ){ + if (loop_cnt >= 20 && totalDistWrited != totalDist ){ eeprom_write_block(&totalDist,totalDistMemLocation,2); - totalDistWrited = totalDist; + totalDistWrited = int(totalDist); loop_cnt = 0; } } @@ -303,7 +302,7 @@ void calcSpeed() { speed = speed_last_3; } speed = (speed + speed_last)/2; - totalDist = totalDist + 1; + totalDist = totalDist + (1/MagnetsCnt); } void calcGear() { @@ -435,7 +434,7 @@ void prepareTurnOff() { totalDistWrited = totalDist; loop_cnt = 0; - for (; 1500 < (millis() - lastMillisSpd);) { // zmiana z 1000 na 1500 w 1.13.X + for (; 1500 < (millis() - lastMillisSpd);) { // zmiana z 1000 na 1500 w 1.13.19 digitalWrite(ServoSwitch, LOW); digitalWrite(ServoPin, LOW); //INFO