diff --git a/LeonardoProMicro/AutomatedGearShifter/AutomatedGearShifter.ino b/LeonardoProMicro/AutomatedGearShifter/AutomatedGearShifter.ino index 7dedd05..8b7774e 100644 --- a/LeonardoProMicro/AutomatedGearShifter/AutomatedGearShifter.ino +++ b/LeonardoProMicro/AutomatedGearShifter/AutomatedGearShifter.ino @@ -1,4 +1,4 @@ -#include + #include #include // model servo: DS3218 PRO #include #include @@ -6,18 +6,17 @@ #include #include -#define Version "1.14.0" +#define Version "1.14.3" ////2DO: -//pomiar napięcia na baterii // menu do zmiany zakresu predkosci biegów -// menu do zmiany zakresu kątów biegów +// menu do zmiany zakresu kątów biegów, obwodu koła, ilosci magnesow #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 64 #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); -#define PinInterrupt 0 //on board: RX deklaracja pod stabilizacje TX +#define PinInterrupt 0 //on board: RX deklaracja pod stabilizacje TX #define PinInSpeed 1 //on board: TX #define ServoSwitch 4 //on board: 4 #define ServoPin 8 //on board: 8 @@ -80,12 +79,6 @@ int servoCurrPos = ServoMaxAngle; int gearBarHeight = 0; int gearBarPosition = 0; float speedForBar = 0; -//oth -int BrakingLightSwitch; -int ups = 0; -int downs = 0; -int run_hrs = 0; -int run_mins = 0; //DST int totalDistMemLocation = 60; int loop_cnt = 0; @@ -101,6 +94,12 @@ float inputVoltage = 0.0; float measuredVoltage = 0.0; int voltBarHeight = 0; int voltBarPosition = 0; +//oth +int BrakingLightSwitch; +int ups = 0; +int downs = 0; +int run_hrs = 0; +int run_mins = 0; void setup() { //SERVO digitalWrite(ServoSwitch, HIGH); @@ -165,7 +164,7 @@ void setup() { } //MEMORY eeprom_read_block(&totalDistReaded, totalDistMemLocation, 2); - totalDist = totalDistReaded; + totalDist = float(totalDistReaded); } //########################################### LOOP ############################################################ @@ -212,9 +211,9 @@ void loop() { //duzy font //GEAR - display.setCursor(3, 0); + display.setCursor(8, 0); display.println("G:"); - display.setCursor(35, 0); + display.setCursor(40, 0); display.print(currentGear); //SPEED_TREND display.setCursor(100, 00); @@ -228,9 +227,9 @@ void loop() { } } //SPEED - display.setCursor(3, 40); + display.setCursor(8, 40); display.println("S:"); - display.setCursor(35, 40); + display.setCursor(40, 40); display.println(speed, 1); //GearBar currentGearRangeMiddle = (currentGearRangeLower + currentGearRangeUpper) / 2; @@ -252,7 +251,7 @@ void loop() { measuredVoltage = (adcBattVoltValue * referenceVoltage) / maxADCValue; inputVoltage = measuredVoltage * voltageDividerRatio; - voltBarHeight = int(((inputVoltage-9)/3.6)*64); + voltBarHeight = int(((inputVoltage-9)/3)*64); //odjemowanie 9 bo to minimalne napiecie, podział przez 3 bo zakladam max napiecie 12.0V a nie 12.6V voltBarPosition = 64 - voltBarHeight; display.fillRect(0, voltBarPosition, 1, voltBarHeight, SSD1306_WHITE); //########################################## ZAPIS DO WYŚWIETLACZA ###################################################### @@ -280,9 +279,10 @@ void loop() { //TTL DST // totalDist = 0; loop_cnt = loop_cnt +1; - if (loop_cnt >= 20 && totalDistWrited != totalDist ){ - eeprom_write_block(&totalDist,totalDistMemLocation,2); + if (loop_cnt >= 20 //&& totalDistWrited != totalDist + ){ totalDistWrited = int(totalDist); +// eeprom_write_block(&totalDistWrited,totalDistMemLocation,2); loop_cnt = 0; } } @@ -430,10 +430,11 @@ void prepareTurnOff() { myservo.write(servoCurrPos); delay(30); } - eeprom_write_block(&totalDist,totalDistMemLocation,2); - totalDistWrited = totalDist; - loop_cnt = 0; - +//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 digitalWrite(ServoSwitch, LOW); digitalWrite(ServoPin, LOW);