Poprawa wyliczania speedTrend
Porządki
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
#include <Adafruit_GFX.h>
|
#include <Adafruit_GFX.h>
|
||||||
#include <Adafruit_SSD1306.h>
|
#include <Adafruit_SSD1306.h>
|
||||||
|
|
||||||
#define Version "2.2.0"
|
#define Version "2.2.3"
|
||||||
////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 changeDelayMs = 1000.0;
|
double speedDiff = 1.0;
|
||||||
double accelerationShift = 1.0;
|
double accelerationShift = 1.0;
|
||||||
int displGear = 9 - currentGear;
|
int displGear = 9 - currentGear;
|
||||||
float currentGearRangeLower = 0;
|
float currentGearRangeLower = 0;
|
||||||
@@ -83,10 +83,8 @@ float currentGearRangeUpper = 7.5;
|
|||||||
int pos = 0;
|
int pos = 0;
|
||||||
int sleepMode = 0;
|
int sleepMode = 0;
|
||||||
int servoCurrPos = ServoMaxAngle;
|
int servoCurrPos = ServoMaxAngle;
|
||||||
//GearBar
|
//GearRangePointer
|
||||||
int gearBarHeight = 0;
|
int pointerPosition = 0;
|
||||||
int gearBarPosition = 0;
|
|
||||||
float speedForBar = 0;
|
|
||||||
unsigned int pointerVisibility = 1;
|
unsigned int pointerVisibility = 1;
|
||||||
//BATTERY
|
//BATTERY
|
||||||
float referenceVoltage = 3.3;
|
float referenceVoltage = 3.3;
|
||||||
@@ -263,7 +261,7 @@ void calcSpeed(){
|
|||||||
calcSpeedAvg = (calcSpeed1 + calcSpeed2 + calcSpeed3)/3;
|
calcSpeedAvg = (calcSpeed1 + calcSpeed2 + calcSpeed3)/3;
|
||||||
calcSpeedMain = calcSpeedAvg;
|
calcSpeedMain = calcSpeedAvg;
|
||||||
|
|
||||||
if(abs(raw_speed - calcSpeed2) >= changeDelayMs) {
|
if(abs(raw_speed - calcSpeed2) >= speedDiff) {
|
||||||
if ((raw_speed - calcSpeed2) < 0) {
|
if ((raw_speed - calcSpeed2) < 0) {
|
||||||
speedTrend = -1;
|
speedTrend = -1;
|
||||||
|
|
||||||
@@ -314,9 +312,14 @@ void calcGear() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
calcTimeDiff = millis() - lastGearCalc;
|
calcTimeDiff = millis() - lastGearCalc;
|
||||||
if (calcTimeDiff < 2000 && abs((calculatedGear-currentGear))<=1){
|
if (calcTimeDiff < 2000 && abs((calculatedGear-currentGear)) <= 1){
|
||||||
currentGear = currentGear;
|
currentGear = currentGear;
|
||||||
pointerVisibility = 0;
|
if (abs((calculatedGear-currentGear)) > 0){
|
||||||
|
pointerVisibility = 0;
|
||||||
|
|
||||||
|
}else {
|
||||||
|
pointerVisibility = 1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
currentGear = calculatedGear;
|
currentGear = calculatedGear;
|
||||||
lastGearCalc = millis();
|
lastGearCalc = millis();
|
||||||
@@ -386,14 +389,14 @@ void loop() {
|
|||||||
display.println("S:");
|
display.println("S:");
|
||||||
display.setCursor(40, 40);
|
display.setCursor(40, 40);
|
||||||
display.println(calcSpeedMain, 1);
|
display.println(calcSpeedMain, 1);
|
||||||
//GearBar
|
//GearRangePointer
|
||||||
if (pointerVisibility = 1){
|
if (pointerVisibility == 1){
|
||||||
display.fillRect(115, 32, 7, 1, SSD1306_WHITE);
|
display.fillRect(115, 32, 7, 1, SSD1306_WHITE);
|
||||||
display.fillRect(115, 0, 7, 1, SSD1306_WHITE);
|
display.fillRect(115, 0, 7, 1, SSD1306_WHITE);
|
||||||
display.fillRect(115, 63, 7, 1, SSD1306_WHITE);
|
display.fillRect(115, 63, 7, 1, SSD1306_WHITE);
|
||||||
display.setTextSize(2);
|
display.setTextSize(2);
|
||||||
gearBarHeight = 64 - int(((calcSpeedMain - currentGearRangeLower) / (currentGearRangeUpper - currentGearRangeLower)) * 64) - 5;
|
pointerPosition = 64 - int(((calcSpeedMain - currentGearRangeLower) / (currentGearRangeUpper - currentGearRangeLower)) * 64) - 5;
|
||||||
display.setCursor(115, gearBarHeight);
|
display.setCursor(115, pointerPosition);
|
||||||
display.write(16);
|
display.write(16);
|
||||||
display.setTextSize(3);
|
display.setTextSize(3);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user