Milestone: Quiz 1 done. 3 NFC readers are connected. If reader 1 can read a UID the temperature decreases on all other readers it increases. Temperature is displayed on single LED strip
This commit is contained in:
1 parent
a84ba0e60a
commit
b075f473f7
1 file changed
+47
-87
+47
-87
@@ -92,97 +92,65 @@ boolean getCardID(Adafruit_PN532 &nfc, uint8_t *uid, uint8_t &uidLength) {
|
||||
return success;
|
||||
}
|
||||
|
||||
const unsigned long CARD_TIMEOUT_MS = 2000;
|
||||
|
||||
unsigned long lastSeen1 = 0;
|
||||
unsigned long lastSeen2 = 0;
|
||||
unsigned long lastSeen3 = 0;
|
||||
|
||||
UIDResult result1 = UID_NONE;
|
||||
UIDResult result2 = UID_NONE;
|
||||
UIDResult result3 = UID_NONE;
|
||||
|
||||
/**************************************************************************/
|
||||
void loop(void) {
|
||||
|
||||
delay(50); // Static
|
||||
delay(50);
|
||||
|
||||
const int8_t DEFAULT_TEMP = 24;
|
||||
int8_t temperature = DEFAULT_TEMP;
|
||||
|
||||
//RFID readers
|
||||
boolean success1;
|
||||
boolean success2;
|
||||
boolean success3;
|
||||
uint8_t uid1[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
|
||||
uint8_t uid2[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
|
||||
uint8_t uid3[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID
|
||||
uint8_t uidLength1 = 7; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
|
||||
uint8_t uidLength2 = 7; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
|
||||
uint8_t uidLength3 = 7; // Length of the UID (4 or 7 bytes depending on ISO14443A card type)
|
||||
unsigned long now = millis();
|
||||
|
||||
uint8_t uid1[7], uid2[7], uid3[7];
|
||||
uint8_t uidLength1 = 0, uidLength2 = 0, uidLength3 = 0;
|
||||
|
||||
//Reader 01--------------
|
||||
success1 = getCardID(nfc, uid1, uidLength1);
|
||||
success2 = getCardID(nfc2, uid2, uidLength2);
|
||||
success3 = getCardID(nfc3, uid3, uidLength3);
|
||||
|
||||
int8_t temperature = 24;
|
||||
|
||||
if(result1 == UID_RIGHT){
|
||||
temperature = temperature - 6;
|
||||
}else if (result1 == UID_WRONG) {
|
||||
temperature = temperature + 6;
|
||||
}
|
||||
else {
|
||||
// -------- Reader 1 --------
|
||||
if (getCardID(nfc, uid1, uidLength1)) {
|
||||
lastSeen1 = now;
|
||||
}
|
||||
|
||||
if(result2 == UID_RIGHT){
|
||||
temperature = temperature - 6;
|
||||
}else if (result2 == UID_WRONG) {
|
||||
temperature = temperature + 6;
|
||||
}
|
||||
else {
|
||||
}
|
||||
if(result3 == UID_RIGHT){
|
||||
temperature = temperature - 6;
|
||||
}else if (result3 == UID_WRONG) {
|
||||
temperature = temperature + 6;
|
||||
}
|
||||
else {
|
||||
// -------- Reader 2 --------
|
||||
if (getCardID(nfc2, uid2, uidLength2)) {
|
||||
lastSeen2 = now;
|
||||
}
|
||||
|
||||
if (success1) {
|
||||
Serial.println("First reader found a card!");
|
||||
Serial.print("UID Length: ");Serial.print(uidLength1, DEC);Serial.println(" bytes");
|
||||
Serial.print("UID Value: ");
|
||||
for (uint8_t i=0; i < uidLength1; i++)
|
||||
{
|
||||
Serial.print(" 0x");Serial.print(uid1[i], HEX);
|
||||
}
|
||||
Serial.println("");
|
||||
result1 = checkUID(uid1, uidLength1);
|
||||
// -------- Reader 3 --------
|
||||
if (getCardID(nfc3, uid3, uidLength3)) {
|
||||
lastSeen3 = now;
|
||||
}
|
||||
|
||||
if (success2) {
|
||||
Serial.println("Second reader found a card!");
|
||||
Serial.print("UID Length: ");Serial.print(uidLength2, DEC);Serial.println(" bytes");
|
||||
Serial.print("UID Value: ");
|
||||
for (uint8_t i=0; i < uidLength2; i++)
|
||||
{
|
||||
Serial.print(" 0x");Serial.print(uid2[i], HEX);
|
||||
}
|
||||
Serial.println("");
|
||||
result2 = checkUID(uid2, uidLength2);
|
||||
// -------- Presence check (2s timeout) --------
|
||||
bool reader1Active = (now - lastSeen1) < CARD_TIMEOUT_MS;
|
||||
bool reader2Active = (now - lastSeen2) < CARD_TIMEOUT_MS;
|
||||
bool reader3Active = (now - lastSeen3) < CARD_TIMEOUT_MS;
|
||||
|
||||
if (reader1Active) {
|
||||
Serial.println("Reader 1 active");
|
||||
temperature -= 6;
|
||||
}
|
||||
|
||||
if (success3) {
|
||||
Serial.println("Third reader found a card!");
|
||||
Serial.print("UID Length: ");Serial.print(uidLength3, DEC);Serial.println(" bytes");
|
||||
Serial.print("UID Value: ");
|
||||
for (uint8_t i=0; i < uidLength3; i++)
|
||||
{
|
||||
Serial.print(" 0x");Serial.print(uid3[i], HEX);
|
||||
if (reader2Active) {
|
||||
Serial.println("Reader 2 active");
|
||||
temperature += 6;
|
||||
}
|
||||
Serial.println("");
|
||||
result3 = checkUID(uid3, uidLength3);
|
||||
|
||||
if (reader3Active) {
|
||||
Serial.println("Reader 3 active");
|
||||
temperature += 6;
|
||||
}
|
||||
|
||||
temperature = constrain(temperature, 0, NUM_LEDS - 12);
|
||||
displayTemp(temperature);
|
||||
}
|
||||
|
||||
|
||||
void displayTemp(uint8_t temp) {
|
||||
|
||||
// Clamp temp so we don’t overflow the strip
|
||||
@@ -200,10 +168,8 @@ void displayTemp(uint8_t temp) {
|
||||
// Bottom 6 LEDs solid BLUE
|
||||
for (int i = 12; i < 18; i++) {
|
||||
CRGB color = blue;
|
||||
|
||||
uint8_t scale = (i < brightEnd) ? BRIGHT_SCALE : DIM_SCALE;
|
||||
color.nscale8_video(scale);
|
||||
|
||||
leds[i] = color;
|
||||
}
|
||||
|
||||
@@ -214,30 +180,24 @@ void displayTemp(uint8_t temp) {
|
||||
uint8_t eased = ease8InOutQuad(pos);
|
||||
CRGB color = blend(blue, red, eased);
|
||||
|
||||
uint8_t scale;
|
||||
if (i < brightEnd) {
|
||||
scale = BRIGHT_SCALE; // temp-controlled brightness
|
||||
} else {
|
||||
scale = (i < 36) ? BRIGHT_SCALE : DIM_SCALE; // original behavior
|
||||
}
|
||||
|
||||
color.nscale8_video(scale);
|
||||
leds[i] = color;
|
||||
}
|
||||
|
||||
// Top 6 LEDs solid RED
|
||||
for (int i = 54; i < NUM_LEDS; i++) {
|
||||
CRGB color = red;
|
||||
|
||||
uint8_t scale = (i < brightEnd) ? BRIGHT_SCALE : DIM_SCALE;
|
||||
color.nscale8_video(scale);
|
||||
|
||||
leds[i] = color;
|
||||
}
|
||||
|
||||
// Top 6 LEDs solid RED
|
||||
for (int i = 54; i < NUM_LEDS; i++) {
|
||||
CRGB color = red;
|
||||
uint8_t scale = (i < brightEnd) ? BRIGHT_SCALE : DIM_SCALE;
|
||||
color.nscale8_video(scale);
|
||||
leds[i] = color;
|
||||
}
|
||||
|
||||
FastLED.show();
|
||||
}
|
||||
|
||||
|
||||
// ---- Known UIDs ----
|
||||
|
||||
// Right answers (4-byte UIDs)
|
||||
|
||||
Reference in new issue
Block a user