Uusnięcie zbędnego kodu

Przywrócenie SpeedTrend
Przywrócenie migania światła stop
This commit is contained in:
sieja
2025-06-15 17:14:20 +02:00
parent ccd190ec40
commit 913a6d1f15

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.1.4" #define Version "2.2.0"
////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
@@ -40,7 +40,6 @@ Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
Servo myservo; Servo myservo;
//SPEED //SPEED
double readSignalTime_5; double readSignalTime_5;
double readSignalTime_4; double readSignalTime_4;
@@ -62,20 +61,8 @@ unsigned long millissSpd = millis();
unsigned long lastMillisSpd = millis(); unsigned long lastMillisSpd = millis();
unsigned long lastLastMillisSpd = millis(); unsigned long lastLastMillisSpd = millis();
unsigned long loopTime = millis(); unsigned long loopTime = millis();
//speed validation
double speed4Gear = 0.0;
double speed4Gear_1 = 0.0;
double speed4Gear_2 = 0.0;
double speed4Gear_3 = 0.0;
double speed4Geat_estimated = 0.0;
double speedDiff_1 = 0.0;
double speedDiff_2 = 0.0;
double speedDiff_3 = 0.0;
int avgWeight_2 = 2;
int avgWeight_3 = 1;
//GEAR //GEAR
int currentGear = 1; int currentGear = 1;
int previousGear = 1;
int calculatedGear = 1; int calculatedGear = 1;
//Przedziały dia biegów //Przedziały dia biegów
float spdRange1and2 = 7.5; float spdRange1and2 = 7.5;
@@ -87,11 +74,10 @@ 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 = 2000.0; double changeDelayMs = 1000.0;
double accelerationShift = 1.0; double accelerationShift = 1.0;
int displGear = 9 - currentGear; int displGear = 9 - currentGear;
float currentGearRangeLower = 0; float currentGearRangeLower = 0;
float currentGearRangeMiddle = 3.0;
float currentGearRangeUpper = 7.5; float currentGearRangeUpper = 7.5;
//SERVO //SERVO
int pos = 0; int pos = 0;
@@ -101,12 +87,7 @@ int servoCurrPos = ServoMaxAngle;
int gearBarHeight = 0; int gearBarHeight = 0;
int gearBarPosition = 0; int gearBarPosition = 0;
float speedForBar = 0; float speedForBar = 0;
//DST unsigned int pointerVisibility = 1;
int totalDistMemLocation = 60;
int loop_cnt = 0;
double totalDist = 0.0;
unsigned int totalDistReaded = 0;
unsigned int totalDistWrited = 0;
//BATTERY //BATTERY
float referenceVoltage = 3.3; float referenceVoltage = 3.3;
int maxADCValue = 4095; int maxADCValue = 4095;
@@ -118,8 +99,6 @@ int voltBarHeight = 0;
int voltBarPosition = 0; int voltBarPosition = 0;
//oth //oth
int BrakingLightSwitch; int BrakingLightSwitch;
int ups = 0;
int downs = 0;
int run_hrs = 0; int run_hrs = 0;
int run_mins = 0; int run_mins = 0;
void setup() { void setup() {
@@ -127,14 +106,7 @@ void setup() {
digitalWrite(ServoSwitch, HIGH); digitalWrite(ServoSwitch, HIGH);
myservo.attach(ServoPin); // attaches the servo on pin 4 to the servo object myservo.attach(ServoPin); // attaches the servo on pin 4 to the servo object
setPosition(8); setPosition(8);
//
// Serial.begin(9600);
// //DIPLAY settings
// if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
// Serial.println(F("SSD1306 allocation failed"));
// for (;;); // Don't proceed, loop forever
// }
display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS); display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);
display.clearDisplay(); display.clearDisplay();
display.setTextColor(WHITE); display.setTextColor(WHITE);
@@ -187,10 +159,6 @@ void setup() {
myservo.write(servoCurrPos); myservo.write(servoCurrPos);
delay(15); delay(15);
} }
//MEMORY
// eeprom_read_block(&totalDistReaded, totalDistMemLocation, 2);
// totalDist = float(totalDistReaded);
} }
@@ -226,7 +194,6 @@ void readSpeed() {
readSignalTimeAvg = (readSignalTime_1 + readSignalTime_2 + readSignalTime_3 )/3; readSignalTimeAvg = (readSignalTime_1 + readSignalTime_2 + readSignalTime_3 )/3;
raw_speed = (((2 * Pi) / readSignalTimeAvg * ((WheelCircumference) / (Pi)) * ms2kmh)) / MagnetsCnt; raw_speed = (((2 * Pi) / readSignalTimeAvg * ((WheelCircumference) / (Pi)) * ms2kmh)) / MagnetsCnt;
} }
@@ -241,11 +208,7 @@ void prepareTurnOff() {
myservo.write(servoCurrPos); myservo.write(servoCurrPos);
delay(15); delay(15);
} }
//Na czas diagnostyki
// eeprom_write_block(&totalDist,totalDistMemLocation,2);
// totalDistWrited = totalDist;
// loop_cnt = 0;
//
for (; 1500 < (millis() - lastMillisSpd);) { // zmiana z 1000 na 1500 w 1.13.19 for (; 1500 < (millis() - lastMillisSpd);) { // zmiana z 1000 na 1500 w 1.13.19
digitalWrite(ServoSwitch, LOW); digitalWrite(ServoSwitch, LOW);
digitalWrite(ServoPin, LOW); digitalWrite(ServoPin, LOW);
@@ -264,22 +227,11 @@ void prepareTurnOff() {
display.println("+"); display.println("+");
display.setCursor(15, 0); display.setCursor(15, 0);
display.write(30); display.write(30);
display.setCursor(25, 0);
display.println(downs + ups);
//Version //Version
display.setCursor(5, 13); display.setCursor(5, 13);
display.println("V: "); display.println("V: ");
display.setCursor(15, 13); display.setCursor(15, 13);
display.println(Version); display.println(Version);
//DST
display.setCursor(50, 0);
display.println("Spins: ");
display.setCursor(85, 0);
display.println(totalDistWrited);
display.setCursor(58, 13);
display.println("KM: ");
display.setCursor(95, 13);
display.println((totalDistWrited*WheelCircumference)/1000);
//RUN TIME //RUN TIME
run_mins = floor((millis() / 1000) / 60); run_mins = floor((millis() / 1000) / 60);
run_hrs = floor(run_mins / 60); run_hrs = floor(run_mins / 60);
@@ -299,7 +251,6 @@ void prepareTurnOff() {
voltBarPosition = 64 - voltBarHeight; voltBarPosition = 64 - voltBarHeight;
display.fillRect(0, voltBarPosition, 2, voltBarHeight, SSD1306_WHITE); display.fillRect(0, voltBarPosition, 2, voltBarHeight, SSD1306_WHITE);
display.display(); display.display();
delay(500); delay(500);
} }
} }
@@ -311,6 +262,17 @@ void calcSpeed(){
calcSpeedAvg = (calcSpeed1 + calcSpeed2 + calcSpeed3)/3; calcSpeedAvg = (calcSpeed1 + calcSpeed2 + calcSpeed3)/3;
calcSpeedMain = calcSpeedAvg; calcSpeedMain = calcSpeedAvg;
if(abs(raw_speed - calcSpeed2) >= changeDelayMs) {
if ((raw_speed - calcSpeed2) < 0) {
speedTrend = -1;
} else {
speedTrend = 1;
}
}else {
speedTrend = 0;
}
} }
void calcGear() { void calcGear() {
accelerationShift = 1; accelerationShift = 1;
@@ -352,16 +314,23 @@ void calcGear() {
}; };
calcTimeDiff = millis() - lastGearCalc; calcTimeDiff = millis() - lastGearCalc;
// previousGear = currentGear; if (calcTimeDiff < 2000 && abs((calculatedGear-currentGear))<=1){
currentGear = calculatedGear; currentGear = currentGear;
lastGearCalc = millis(); pointerVisibility = 0;
} else {
currentGear = calculatedGear;
lastGearCalc = millis();
pointerVisibility = 1;
}
} }
//########################################### LOOP ############################################################ //########################################### LOOP ############################################################
//########################################### LOOP ############################################################ //########################################### LOOP ############################################################
void loop() { void loop() {
loopTime = millis(); loopTime = millis();
@@ -382,8 +351,6 @@ void loop() {
//SPEED //SPEED
sleepSpd = millis() - millissSpd; sleepSpd = millis() - millissSpd;
if (sleepSpd >= 1000.0) { //podaj zerową prędkość jeśli nie było odcztu od 1,5 s if (sleepSpd >= 1000.0) { //podaj zerową prędkość jeśli nie było odcztu od 1,5 s
speed4Gear = 0.0;
speed4Gear_2 = 0.0;
raw_speed = 0.0; raw_speed = 0.0;
} }
//przejście w tryb uśpienia za przuycisku lub czasu //przejście w tryb uśpienia za przuycisku lub czasu
@@ -391,9 +358,6 @@ void loop() {
prepareTurnOff(); prepareTurnOff();
} }
if (speed4Gear > 40 || isinf(speed4Gear)) {
speed4Gear = speed4Gear_3;
}
calcSpeed(); calcSpeed();
calcGear(); calcGear();
displGear = 9 - currentGear; displGear = 9 - currentGear;
@@ -423,18 +387,16 @@ void loop() {
display.setCursor(40, 40); display.setCursor(40, 40);
display.println(calcSpeedMain, 1); display.println(calcSpeedMain, 1);
//GearBar //GearBar
currentGearRangeMiddle = (currentGearRangeLower + currentGearRangeUpper) / 2; 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;
display.setCursor(115, gearBarHeight);
gearBarHeight = 64 - int(((calcSpeedMain - currentGearRangeLower) / (currentGearRangeUpper - currentGearRangeLower)) * 64) - 5; display.write(16);
display.setCursor(115, gearBarHeight); display.setTextSize(3);
display.write(16); }
display.setTextSize(3);
//VOLT_BAR //VOLT_BAR
adcBattVoltValue = analogRead(VoltInptPin); adcBattVoltValue = analogRead(VoltInptPin);
@@ -460,7 +422,7 @@ void loop() {
if (speedTrend == -1 && speed4Gear > 0.0 ) { if (speedTrend == -1 ) {
if (BrakingLightSwitch == 1) { if (BrakingLightSwitch == 1) {
digitalWrite(BrakingLight, HIGH); digitalWrite(BrakingLight, HIGH);
BrakingLightSwitch = 0; BrakingLightSwitch = 0;
@@ -471,15 +433,6 @@ void loop() {
} else { } else {
digitalWrite(BrakingLight, LOW); digitalWrite(BrakingLight, LOW);
} }
// //TTL DST
// // totalDist = 0;
// loop_cnt = loop_cnt +1;
// if (loop_cnt >= 20 //&& totalDistWrited != totalDist
// ){
// totalDistWrited = int(totalDist);
// // eeprom_write_block(&totalDistWrited,totalDistMemLocation,2);
// loop_cnt = 0;
// }
} }
//########################################### LOOP ############################################################ //########################################### LOOP ############################################################