Poprawa wyliczania speedTrend
Porządki
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user