zadeklarowanie  PinInterrupt 0 w celu zminimalizowania efektu anteny z drugiego pinu
zapis do pamięci co 2,5sec + 10 obrotów
korekty na ekranie uśpienia
This commit is contained in:
Kamil Siejka
2024-10-13 15:47:07 +02:00
parent 8d6c4fae44
commit 005e4dd65d

View File

@@ -1,4 +1,4 @@
//#include <avr/eeprom.h> #include <avr/eeprom.h>
#include <Servo.h> // model servo: DS3218 PRO #include <Servo.h> // model servo: DS3218 PRO
#include <SPI.h> #include <SPI.h>
#include <Wire.h> #include <Wire.h>
@@ -6,8 +6,7 @@
#include <Adafruit_GFX.h> #include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h> #include <Adafruit_SSD1306.h>
#define Version "1.11.3.1" #define Version "1.12.10"
//ostatnia zmiana: zmiana na PCB, dostrajanie
////2DO: ////2DO:
#define SCREEN_WIDTH 128 #define SCREEN_WIDTH 128
@@ -15,7 +14,8 @@
#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) #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 #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
#define PinInSpeed 1 //on board: RXI #define PinInterrupt 0 //on board: RX deklaracja pod stabilizacje TX
#define PinInSpeed 1 //on board: TX
#define ServoSwitch 4 //on board: 4 #define ServoSwitch 4 //on board: 4
#define ServoPin 8 //on board: 8 #define ServoPin 8 //on board: 8
#define BrakingLight 9 //on board: 9 BrakingLight #define BrakingLight 9 //on board: 9 BrakingLight
@@ -84,9 +84,11 @@ int downs = 0;
int run_hrs = 0; int run_hrs = 0;
int run_mins = 0; int run_mins = 0;
//DST //DST
int totalDist = 0; int totalDistMemLocation = 60;
int totalDistReaded = 0; int loop_cnt = 0;
unsigned int totalDist = 0;
unsigned int totalDistReaded = 0;
unsigned int totalDistWrited = 0;
void setup() { void setup() {
//SERVO //SERVO
@@ -113,7 +115,8 @@ void setup() {
display.display(); display.display();
delay(500); delay(500);
//INPUT //INPUT
pinMode(PinInSpeed, INPUT_PULLUP); pinMode(PinInSpeed, INPUT);
pinMode(PinInterrupt, INPUT_PULLUP);
pinMode(Btn1, INPUT); pinMode(Btn1, INPUT);
//OUTPUT //OUTPUT
pinMode(PinLED, OUTPUT); pinMode(PinLED, OUTPUT);
@@ -122,11 +125,6 @@ void setup() {
//Interrupts //Interrupts
attachInterrupt(digitalPinToInterrupt(PinInSpeed), calcSpeed, FALLING); attachInterrupt(digitalPinToInterrupt(PinInSpeed), calcSpeed, FALLING);
// powolne ustawianie pozycji servo po włączeniu
// delay(750);
// setPosition(8);
display.clearDisplay(); display.clearDisplay();
delay(550); delay(550);
setPosition(7); setPosition(7);
@@ -153,9 +151,8 @@ void setup() {
delay(30); delay(30);
} }
//MEMORY //MEMORY
eeprom_read_block(&totalDistReaded, 0, 2); eeprom_read_block(&totalDistReaded, totalDistMemLocation, 2);
totalDist = totalDistReaded; totalDist = totalDistReaded;
} }
@@ -251,8 +248,15 @@ void loop() {
} else { } else {
digitalWrite(BrakingLight, LOW); digitalWrite(BrakingLight, LOW);
} }
// //TTL DST //TTL DST
// eeprom_write_block(&totalDist,0,2); // totalDist = 0;
loop_cnt = loop_cnt +1;
if (loop_cnt >= 10 && totalDistWrited != totalDist ){
eeprom_write_block(&totalDist,totalDistMemLocation,2);
totalDistWrited = totalDist;
loop_cnt = 0;
}
} }
@@ -266,11 +270,11 @@ void calcSpeed() {
speed_last = speed; speed_last = speed;
speed = (((2 * Pi) / sigleTimeSpd * ((WheelCircumference) / (Pi)) * ms2kmh)) / MagnetsCnt; speed = (((2 * Pi) / sigleTimeSpd * ((WheelCircumference) / (Pi)) * ms2kmh)) / MagnetsCnt;
// diag // diag
// if (((speed_last_3 * 1.5) > speed) && speed > 10.0 && speedTrend > 0) { //zabezpieczenie przed losowymi sygnałami magesu if (((speed_last_3 * 1.5) > speed) && speed > 10.0 && speedTrend > 0) { //zabezpieczenie przed losowymi sygnałami magesu
// speed = speed_last_3; speed = speed_last_3;
// } }
// speed = (speed + speed_last)/2; speed = (speed + speed_last)/2;
// totalDist = totalDist + 1; totalDist = totalDist + 1;
} }
void calcGear() { void calcGear() {
@@ -401,7 +405,7 @@ void prepareTurnOff() {
for (; 1000 < (millis() - lastMillisSpd);) { for (; 1000 < (millis() - lastMillisSpd);) {
digitalWrite(ServoSwitch, LOW); digitalWrite(ServoSwitch, LOW);
digitalWrite(ServoPin, LOW); digitalWrite(ServoPin, LOW);
// myservo.detach(ServoPin); //INFO
display.clearDisplay(); display.clearDisplay();
display.setTextSize(1); display.setTextSize(1);
display.setCursor(0, 30); display.setCursor(0, 30);
@@ -418,22 +422,34 @@ void prepareTurnOff() {
display.write(30); display.write(30);
display.setCursor(20, 0); display.setCursor(20, 0);
display.println(downs + ups); display.println(downs + ups);
//Version
display.setCursor(0, 13);
display.println("V: ");
display.setCursor(10, 13);
display.println(Version);
//DST
eeprom_write_block(&totalDist,totalDistMemLocation,2);
totalDistWrited = totalDist;
loop_cnt = 0;
display.setCursor(45, 0);
display.println("Spins: "); display.println("Spins: ");
display.setCursor(60, 0); display.setCursor(80, 0);
display.println(totalDist);; display.println(totalDistWrited);
display.setCursor(70, 0); display.setCursor(53, 13);
display.println("KM: ");
display.setCursor(90, 13);
display.println((totalDistWrited*WheelCircumference)/1000);
//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);
run_mins = run_mins - (run_hrs * 60); run_mins = run_mins - (run_hrs * 60);
display.setCursor(64, 54); display.setCursor(60, 54);
display.println("T:"); display.println("T:");
display.setCursor(75, 54); display.setCursor(75, 54);
display.println(run_hrs); display.println(run_hrs);
display.setCursor(80, 54); display.setCursor(83, 54);
display.println(":"); display.println(":");
display.setCursor(85, 54); display.setCursor(88, 54);
display.println(run_mins); display.println(run_mins);
display.display(); display.display();
delay(500); delay(500);