Enable RFID UID output and tidy car mass input
This commit is contained in:
+13
-20
@@ -21,28 +21,21 @@ bool seatBelts = false;
|
|||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
|
||||||
// -----------------------------------------------------------------
|
Serial.println(F("Enter car mass in kg (e.g. 1200):"));
|
||||||
// 1. Ask the user for the car mass (kg) via the Serial monitor.
|
while (true) {
|
||||||
// We block only until a valid number is received – this is OK
|
if (Serial.available() > 0) {
|
||||||
// because it happens once at startup.
|
float mass = Serial.parseFloat();
|
||||||
// -----------------------------------------------------------------
|
if (mass > 0) {
|
||||||
Serial.println(F("Enter car mass in kg (e.g. 1200):"));
|
engine.setCarMass(mass);
|
||||||
while (true) {
|
Serial.print(F("Car mass set to "));
|
||||||
// Wait until something is typed
|
Serial.print(mass);
|
||||||
if (Serial.available() > 0) {
|
Serial.println(F(" kg"));
|
||||||
float mass = Serial.parseFloat(); // reads the number
|
break;
|
||||||
if (mass > 0) { // basic sanity check
|
} else {
|
||||||
engine.setCarMass(mass);
|
Serial.println(F("Invalid value – try again:"));
|
||||||
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_1, OUTPUT);
|
||||||
pinMode(IN_2, OUTPUT);
|
pinMode(IN_2, OUTPUT);
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ void RFIDReader::begin() {
|
|||||||
bool RFIDReader::check() {
|
bool RFIDReader::check() {
|
||||||
if (!_rfid.PICC_IsNewCardPresent()) return false;
|
if (!_rfid.PICC_IsNewCardPresent()) return false;
|
||||||
if (!_rfid.PICC_ReadCardSerial()) return false;
|
if (!_rfid.PICC_ReadCardSerial()) return false;
|
||||||
// _rfid.PICC_HaltA(); // stop the tag
|
|
||||||
// _rfid.PCD_StopCrypto1(); // clear RC522 crypto
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,10 +29,10 @@ bool RFIDReader::matches(const byte* expectedUid, byte expectedSize) const {
|
|||||||
|
|
||||||
void RFIDReader::printUID() const {
|
void RFIDReader::printUID() const {
|
||||||
Serial.println(F("RFID Tag UID:"));
|
Serial.println(F("RFID Tag UID:"));
|
||||||
// for (byte i = 0; i < _rfid.uid.size; i++) {
|
for (byte i = 0; i < _rfid.uid.size; i++) {
|
||||||
// Serial.print(_rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");
|
Serial.print(_rfid.uid.uidByte[i] < 0x10 ? " 0" : " ");
|
||||||
// Serial.print(_rfid.uid.uidByte[i], HEX);
|
Serial.print(_rfid.uid.uidByte[i], HEX);
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const byte* RFIDReader::getUID() const {
|
const byte* RFIDReader::getUID() const {
|
||||||
|
|||||||
Reference in New Issue
Block a user