Dodanie battery bar, zmiana podejscia do wygaszania
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
|
||||
#include <avr/eeprom.h>
|
||||
#include <Servo.h> // model servo: DS3218 PRO
|
||||
#include <SPI.h>
|
||||
@@ -6,8 +7,11 @@
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
|
||||
#define Version "1.12.12"
|
||||
#define Version "1.13.17"
|
||||
////2DO:
|
||||
//pomiar napięcia na baterii
|
||||
// menu do zmiany zakresu predkosci biegów
|
||||
// menu do zmiany zakresu kątów biegów
|
||||
|
||||
#define SCREEN_WIDTH 128
|
||||
#define SCREEN_HEIGHT 64
|
||||
@@ -20,8 +24,8 @@ Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||
#define ServoPin 8 //on board: 8
|
||||
#define BrakingLight 9 //on board: 9 BrakingLight
|
||||
#define PinLED 10 //on board: 10 ORANGE loop signal
|
||||
#define Btn1 18 //on board: A0 Button0
|
||||
#define Btn2 19 //on board: A1 Button1
|
||||
#define Btn1 18 //on board: A0 Button1
|
||||
#define VoltInptPin 19 //on board: A1 Battery Voltage
|
||||
|
||||
#define ServoMaxAngle 130
|
||||
#define MaxAngle 179
|
||||
@@ -32,7 +36,7 @@ Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
|
||||
#define MagnetsCnt 4
|
||||
#define ms2kmh 3.6
|
||||
#define Pi 3.1416
|
||||
#define TimeToSleep 180000 //3 min
|
||||
#define TimeToSleep 5000 //5 sec
|
||||
|
||||
Servo myservo;
|
||||
|
||||
@@ -89,6 +93,14 @@ int loop_cnt = 0;
|
||||
unsigned int totalDist = 0;
|
||||
unsigned int totalDistReaded = 0;
|
||||
unsigned int totalDistWrited = 0;
|
||||
//BATTERY
|
||||
float referenceVoltage = 5.1;
|
||||
int maxADCValue = 1023;
|
||||
float voltageDividerRatio = 3.0;
|
||||
int adcBattVoltValue = 0;
|
||||
float inputVoltage = 0.0;
|
||||
float measuredVoltage = 0.0;
|
||||
|
||||
|
||||
void setup() {
|
||||
//SERVO
|
||||
@@ -119,6 +131,7 @@ void setup() {
|
||||
pinMode(PinInterrupt, OUTPUT);
|
||||
digitalWrite(PinInterrupt, HIGH);
|
||||
pinMode(Btn1, INPUT);
|
||||
pinMode(VoltInptPin, INPUT);
|
||||
//OUTPUT
|
||||
pinMode(PinLED, OUTPUT);
|
||||
pinMode(BrakingLight, OUTPUT);
|
||||
@@ -161,6 +174,16 @@ void loop() {
|
||||
|
||||
loopTime = millis();
|
||||
display.clearDisplay();
|
||||
// //DIAG Btn1
|
||||
// display.setTextSize(1);
|
||||
// display.setCursor(0, 30);
|
||||
// display.println("Btn1:");
|
||||
// display.setCursor(30, 20);
|
||||
// display.println(digitalRead(Btn1));
|
||||
// display.setCursor(30, 30);
|
||||
// display.println(analogRead(Btn1));
|
||||
// display.setCursor(55, 30);
|
||||
|
||||
display.setTextSize(3);
|
||||
|
||||
//################################################
|
||||
@@ -171,11 +194,15 @@ void loop() {
|
||||
speed_last = 0.0;
|
||||
speed_last_2 = 0.0;
|
||||
speed_last_3 = 0.0;
|
||||
if (sleepSpd >= TimeToSleep) { //ustaw bieg 8. jeśli nie było odcztu od 120 s
|
||||
prepareTurnOff();
|
||||
//przejście w tryb uśpienia za pomocą odpowiedniego ustawienia koła i magnesu
|
||||
if (digitalRead(PinInSpeed) == LOW) {
|
||||
display.fillCircle(75, 10, 10, SSD1306_WHITE);
|
||||
if (sleepSpd >= TimeToSleep) {
|
||||
prepareTurnOff();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//DIAG
|
||||
|
||||
if (speed > 99 || isinf(speed)) {
|
||||
speed = 21.37;
|
||||
}
|
||||
@@ -206,25 +233,26 @@ void loop() {
|
||||
display.setCursor(35, 40);
|
||||
display.println(speed, 1);
|
||||
//GearBar
|
||||
if (sleepSpd <= 30000) {
|
||||
currentGearRangeMiddle = (currentGearRangeLower + currentGearRangeUpper) / 2;
|
||||
display.fillRect(115, 32, 7, 1, SSD1306_WHITE);
|
||||
display.fillRect(115, 0, 7, 1, SSD1306_WHITE);
|
||||
display.fillRect(115, 63, 7, 1, SSD1306_WHITE);
|
||||
|
||||
if (speed >= currentGearRangeMiddle) {
|
||||
gearBarHeight = int(((speedForBar - currentGearRangeMiddle) / (currentGearRangeUpper - currentGearRangeMiddle)) * 32);
|
||||
gearBarPosition = 32 - gearBarHeight;
|
||||
display.fillRect(122, gearBarPosition, 4, gearBarHeight, SSD1306_WHITE);
|
||||
} else {
|
||||
gearBarHeight = int(((currentGearRangeMiddle - speedForBar) / (currentGearRangeMiddle - currentGearRangeLower)) * 32);
|
||||
display.fillRect(122, 32, 4, gearBarHeight, SSD1306_WHITE);
|
||||
}
|
||||
currentGearRangeMiddle = (currentGearRangeLower + currentGearRangeUpper) / 2;
|
||||
display.fillRect(115, 32, 7, 1, SSD1306_WHITE);
|
||||
display.fillRect(115, 0, 7, 1, SSD1306_WHITE);
|
||||
display.fillRect(115, 63, 7, 1, SSD1306_WHITE);
|
||||
|
||||
if (speed >= currentGearRangeMiddle) {
|
||||
gearBarHeight = int(((speedForBar - currentGearRangeMiddle) / (currentGearRangeUpper - currentGearRangeMiddle)) * 32);
|
||||
gearBarPosition = 32 - gearBarHeight;
|
||||
display.fillRect(122, gearBarPosition, 4, gearBarHeight, SSD1306_WHITE);
|
||||
} else {
|
||||
display.setTextSize(2);
|
||||
display.setCursor(90, 25);
|
||||
display.println(int(((TimeToSleep - sleepSpd) / 1000)));
|
||||
gearBarHeight = int(((currentGearRangeMiddle - speedForBar) / (currentGearRangeMiddle - currentGearRangeLower)) * 32);
|
||||
display.fillRect(122, 32, 4, gearBarHeight, SSD1306_WHITE);
|
||||
}
|
||||
|
||||
//VOLT_BAR
|
||||
adcBattVoltValue = analogRead(VoltInptPin);
|
||||
measuredVoltage = (adcBattVoltValue * referenceVoltage) / maxADCValue;
|
||||
inputVoltage = measuredVoltage * voltageDividerRatio;
|
||||
display.fillRect(0, 63, ((inputVoltage-9)/3.6)*124, 1 , SSD1306_WHITE);
|
||||
//########################################## ZAPIS DO WYŚWIETLACZA ######################################################
|
||||
display.display();
|
||||
loopTime = millis();
|
||||
|
||||
@@ -233,10 +261,7 @@ void loop() {
|
||||
delay(10);
|
||||
}
|
||||
|
||||
////przejście w tryb uśpienia za pomocą przycisku
|
||||
if (digitalRead(Btn1) == HIGH) {
|
||||
prepareTurnOff();
|
||||
}
|
||||
|
||||
|
||||
if (speedTrend == -1 && speed > 0.0 ) {
|
||||
if (BrakingLightSwitch == 1) {
|
||||
@@ -256,9 +281,7 @@ void loop() {
|
||||
eeprom_write_block(&totalDist,totalDistMemLocation,2);
|
||||
totalDistWrited = totalDist;
|
||||
loop_cnt = 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void calcSpeed() {
|
||||
@@ -407,7 +430,7 @@ void prepareTurnOff() {
|
||||
totalDistWrited = totalDist;
|
||||
loop_cnt = 0;
|
||||
|
||||
for (; 1000 < (millis() - lastMillisSpd);) {
|
||||
for (; 500 < (millis() - lastMillisSpd);) { // zmiana z 1000 na 500 w 1.13.X
|
||||
digitalWrite(ServoSwitch, LOW);
|
||||
digitalWrite(ServoPin, LOW);
|
||||
//INFO
|
||||
|
||||
BIN
LeonardoProMicro/AutomatedGearShifter/planowanie_pamięci.xlsx
Normal file
BIN
LeonardoProMicro/AutomatedGearShifter/planowanie_pamięci.xlsx
Normal file
Binary file not shown.
BIN
LeonardoProMicro/adafruit-gfx-graphics-library.pdf
Normal file
BIN
LeonardoProMicro/adafruit-gfx-graphics-library.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user