899212d7b9
Define AUTH_UID and AUTH_UID_SIZE constants. Introduce motor control pins IN_1‑IN_4 and set them as outputs. Comment out turn‑signal and sonar pin definitions and related code. Refactor Display to remove updateDirection functionality. Extend RFIDReader with reset() and matches() methods; use them to toggle carEnabled based on RFID authentication. Update the main loop to operate only when the RFID tag matches the authorized UID.
68 lines
1.4 KiB
Arduino
68 lines
1.4 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);
|
|
|
|
unsigned long prevUpdate = 0;
|
|
|
|
bool carEnabled = false;
|
|
|
|
void setup() {
|
|
Serial.begin(9600);
|
|
|
|
// pinMode(TS_LEFT, INPUT);
|
|
// pinMode(TS_RIGHT, INPUT);
|
|
|
|
pinMode(IN_1, OUTPUT);
|
|
pinMode(IN_2, OUTPUT);
|
|
|
|
rfid.begin();
|
|
display.begin(LCD_COLS, LCD_ROWS);
|
|
engine.begin();
|
|
}
|
|
|
|
void loop() {
|
|
bool check = rfid.check();
|
|
bool matches = rfid.matches(AUTH_UID, AUTH_UID_SIZE);
|
|
|
|
bool rfidOk = check && matches;
|
|
|
|
if (rfid.check() && rfid.matches(AUTH_UID, AUTH_UID_SIZE)) {
|
|
delay(3000);
|
|
carEnabled = !carEnabled;
|
|
};
|
|
|
|
if (carEnabled) {
|
|
Serial.println("Działa");
|
|
|
|
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);
|
|
}
|
|
}
|