From 0a4a0b862c9333332613ce48fd5834a27e65f9ba Mon Sep 17 00:00:00 2001 From: GarandPLG Date: Wed, 17 Jun 2026 01:20:39 +0200 Subject: [PATCH] Enable RFID UID output and tidy car mass input --- Projekt_Arduino.ino | 33 +++++++++++++-------------------- RFID.cpp | 10 ++++------ 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/Projekt_Arduino.ino b/Projekt_Arduino.ino index 01d83a2..a818caf 100644 --- a/Projekt_Arduino.ino +++ b/Projekt_Arduino.ino @@ -21,28 +21,21 @@ bool seatBelts = false; void setup() { Serial.begin(9600); - // ----------------------------------------------------------------- - // 1. Ask the user for the car mass (kg) via the Serial monitor. - // We block only until a valid number is received – this is OK - // because it happens once at startup. - // ----------------------------------------------------------------- - Serial.println(F("Enter car mass in kg (e.g. 1200):")); - while (true) { - // Wait until something is typed - if (Serial.available() > 0) { - float mass = Serial.parseFloat(); // reads the number - if (mass > 0) { // basic sanity check - engine.setCarMass(mass); - Serial.print(F("Car mass set to ")); - Serial.print(mass); - Serial.println(F(" kg")); - break; - } else { - Serial.println(F("Invalid value – try again:")); - } + Serial.println(F("Enter car mass in kg (e.g. 1200):")); + while (true) { + if (Serial.available() > 0) { + float mass = Serial.parseFloat(); + if (mass > 0) { + engine.setCarMass(mass); + Serial.print(F("Car mass set to ")); + Serial.print(mass); + Serial.println(F(" kg")); + break; + } else { + Serial.println(F("Invalid value – try again:")); } } - + } pinMode(IN_1, OUTPUT); pinMode(IN_2, OUTPUT); diff --git a/RFID.cpp b/RFID.cpp index 1d58759..27b9a5d 100644 --- a/RFID.cpp +++ b/RFID.cpp @@ -11,8 +11,6 @@ void RFIDReader::begin() { bool RFIDReader::check() { if (!_rfid.PICC_IsNewCardPresent()) return false; if (!_rfid.PICC_ReadCardSerial()) return false; - // _rfid.PICC_HaltA(); // stop the tag - // _rfid.PCD_StopCrypto1(); // clear RC522 crypto return true; } @@ -31,10 +29,10 @@ bool RFIDReader::matches(const byte* expectedUid, byte expectedSize) const { void RFIDReader::printUID() const { Serial.println(F("RFID Tag UID:")); - // for (byte i = 0; i < _rfid.uid.size; i++) { - // Serial.print(_rfid.uid.uidByte[i] < 0x10 ? " 0" : " "); - // Serial.print(_rfid.uid.uidByte[i], HEX); - // } + for (byte i = 0; i < _rfid.uid.size; i++) { + Serial.print(_rfid.uid.uidByte[i] < 0x10 ? " 0" : " "); + Serial.print(_rfid.uid.uidByte[i], HEX); + } } const byte* RFIDReader::getUID() const {