Files
projekt-arduino/Projekt.ino
T
GarandPLG febf1215db Remove debug prints, correct reverse gear, tidy loop
- Comment out all Serial debugging statements and the artificial delay
  in
  Engine::update.
- Change reverse gear detection from `gearIdx == 5` to `gearIdx == -1`.
- Simplify the main loop in Projekt.ino by removing unnecessary braces,
  eliminating temporary blink variables, and calling
  `display.updateDirection`
  directly with the pin reads.
2026-06-16 17:32:31 +02:00

56 lines
1.1 KiB
Arduino

#include <Wire.h>
#include "Config.h"
#include "Display.h"
#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);
pinMode(TS_LEFT, INPUT);
pinMode(TS_RIGHT, INPUT);
rfid.begin();
display.begin(LCD_COLS, LCD_ROWS);
engine.begin();
}
void loop() {
if (gear.update())
display.updateGear(gear.getGearChar());
display.updateDirection(
digitalRead(TS_LEFT),
digitalRead(TS_RIGHT));
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);
if (rfid.check()) {
rfid.printUID();
}
}