Add Engine class and integrate it into Projekt

Add clutch, brake, and throttle pin constants to Config.h.
Implement Engine class in Engine.h/Engine.cpp to read analog inputs,
compute engine RPM, vehicle speed, and apply forces.
Create an Engine instance in Projekt.ino, initialize it in setup,
and update it every 20ms, displaying RPM and speed.
This commit is contained in:
2026-06-16 11:08:56 +02:00
parent d26fb721f9
commit b957a0701b
4 changed files with 160 additions and 0 deletions
+14
View File
@@ -5,15 +5,19 @@
#include "Gear.h"
#include "Sonar.h"
#include "RFID.h"
#include "Engine.h"
Display display;
GearSelector gear(GEAR_X_PIN, GEAR_Y_PIN, GEAR_THRESH_LOW, GEAR_THRESH_HIGH);
Sonar sonar(TRIG_PIN, ECHO_PIN, SONAR_MAX_DIST_CM);
RFIDReader rfid(SS_PIN, RST_PIN);
Engine engine(THROTTLE_PIN, CLUTCH_PIN, BRAKE_PIN);
bool leftBlink = false;
bool rightBlink = false;
unsigned long prevUpdate = 0;
void setup() {
Serial.begin(9600);
@@ -22,6 +26,7 @@ void setup() {
rfid.begin();
display.begin(LCD_COLS, LCD_ROWS);
engine.begin();
}
void loop() {
@@ -33,6 +38,15 @@ void loop() {
rightBlink = digitalRead(TS_RIGHT);
display.updateDirection(leftBlink, rightBlink);
unsigned long now = millis();
float dt = (now - prevUpdate) / 1000.0f;
if (dt >= 0.02f) {
prevUpdate = now;
engine.update(dt, gear.getGear());
display.updateRPM(engine.getRPM());
display.updateSpeed(engine.getSpeedKmh());
}
long dist = sonar.measure();
// Serial.println(dist);