Work In Progress. Added Compare function
This commit is contained in:
1 parent
7768f8d72d
commit
a84ba0e60a
1 file changed
+159
-62
+159
-62
@@ -10,6 +10,13 @@
|
|||||||
#define PN532_SS (4) //orange
|
#define PN532_SS (4) //orange
|
||||||
#define PN532_MISO (5) //green
|
#define PN532_MISO (5) //green
|
||||||
|
|
||||||
|
|
||||||
|
enum UIDResult {
|
||||||
|
UID_NONE,
|
||||||
|
UID_RIGHT,
|
||||||
|
UID_WRONG
|
||||||
|
};
|
||||||
|
|
||||||
// Use this line for a breakout with a SPI connection:
|
// Use this line for a breakout with a SPI connection:
|
||||||
Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, 4); //orange
|
Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, 4); //orange
|
||||||
Adafruit_PN532 nfc2(PN532_SCK, PN532_MISO, PN532_MOSI, 6); //brown
|
Adafruit_PN532 nfc2(PN532_SCK, PN532_MISO, PN532_MOSI, 6); //brown
|
||||||
@@ -72,67 +79,27 @@ void setup(void) {
|
|||||||
setupNFC(nfc3);
|
setupNFC(nfc3);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean getCardID(Adafruit_PN532 nfc, uint8_t *uid ){
|
boolean getCardID(Adafruit_PN532 &nfc, uint8_t *uid, uint8_t &uidLength) {
|
||||||
boolean success;
|
|
||||||
uint8_t uidLength;
|
|
||||||
// Wait for an ISO14443A type cards (Mifare, etc.). When one is found
|
|
||||||
// 'uid' will be populated with the UID, and uidLength will indicate
|
|
||||||
// if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
|
|
||||||
|
|
||||||
//Reader 01--------------
|
// Try to read a card (timeout = 100 ms)
|
||||||
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength, 100);
|
boolean success = nfc.readPassiveTargetID(
|
||||||
|
PN532_MIFARE_ISO14443A,
|
||||||
|
uid,
|
||||||
|
&uidLength,
|
||||||
|
100
|
||||||
|
);
|
||||||
|
|
||||||
if (success) {
|
return success;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
UIDResult result1 = UID_NONE;
|
||||||
|
UIDResult result2 = UID_NONE;
|
||||||
|
UIDResult result3 = UID_NONE;
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
void loop(void) {
|
void loop(void) {
|
||||||
|
|
||||||
// LEDs
|
|
||||||
// --------------------------------------------------
|
|
||||||
|
|
||||||
// First 12 LEDs OFF
|
|
||||||
for (int i = 0; i < 12; i++) {
|
|
||||||
leds[i] = CRGB::Black;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Bottom 6 LEDs solid BLUE
|
|
||||||
for (int i = 12; i < 18; i++) {
|
|
||||||
CRGB color = blue;
|
|
||||||
color.nscale8_video(BRIGHT_SCALE);
|
|
||||||
leds[i] = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Gradient section (between solid colors)
|
|
||||||
for (int i = 18; i < 54; i++) {
|
|
||||||
|
|
||||||
// Map gradient range → 0–255
|
|
||||||
uint8_t pos = map(i, 18, 53, 0, 255);
|
|
||||||
|
|
||||||
// Ease to compress purple
|
|
||||||
uint8_t eased = ease8InOutQuad(pos);
|
|
||||||
|
|
||||||
// Blue → Red blend (no green)
|
|
||||||
CRGB color = blend(blue, red, eased);
|
|
||||||
|
|
||||||
// Bright first half, dim second half
|
|
||||||
uint8_t scale = (i < 36) ? 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;
|
|
||||||
color.nscale8_video(DIM_SCALE);
|
|
||||||
leds[i] = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
FastLED.show();
|
|
||||||
delay(50); // Static
|
delay(50); // Static
|
||||||
|
|
||||||
|
|
||||||
@@ -149,9 +116,34 @@ delay(50); // Static
|
|||||||
|
|
||||||
|
|
||||||
//Reader 01--------------
|
//Reader 01--------------
|
||||||
success1 = getCardID(nfc, &uid1[0]);
|
success1 = getCardID(nfc, uid1, uidLength1);
|
||||||
success2 = getCardID(nfc2, &uid2[0]);
|
success2 = getCardID(nfc2, uid2, uidLength2);
|
||||||
success3 = getCardID(nfc3, &uid3[0]);
|
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 {
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
}
|
||||||
|
|
||||||
if (success1) {
|
if (success1) {
|
||||||
Serial.println("First reader found a card!");
|
Serial.println("First reader found a card!");
|
||||||
@@ -162,6 +154,7 @@ delay(50); // Static
|
|||||||
Serial.print(" 0x");Serial.print(uid1[i], HEX);
|
Serial.print(" 0x");Serial.print(uid1[i], HEX);
|
||||||
}
|
}
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
|
result1 = checkUID(uid1, uidLength1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success2) {
|
if (success2) {
|
||||||
@@ -173,6 +166,7 @@ delay(50); // Static
|
|||||||
Serial.print(" 0x");Serial.print(uid2[i], HEX);
|
Serial.print(" 0x");Serial.print(uid2[i], HEX);
|
||||||
}
|
}
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
|
result2 = checkUID(uid2, uidLength2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success3) {
|
if (success3) {
|
||||||
@@ -184,13 +178,116 @@ delay(50); // Static
|
|||||||
Serial.print(" 0x");Serial.print(uid3[i], HEX);
|
Serial.print(" 0x");Serial.print(uid3[i], HEX);
|
||||||
}
|
}
|
||||||
Serial.println("");
|
Serial.println("");
|
||||||
|
result3 = checkUID(uid3, uidLength3);
|
||||||
}
|
}
|
||||||
}void setup() {
|
displayTemp(temperature);
|
||||||
// put your setup code here, to run once:
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void displayTemp(uint8_t temp) {
|
||||||
// put your main code here, to run repeatedly:
|
|
||||||
|
|
||||||
|
// Clamp temp so we don’t overflow the strip
|
||||||
|
uint8_t maxTempLeds = NUM_LEDS - 12;
|
||||||
|
if (temp > maxTempLeds) temp = maxTempLeds;
|
||||||
|
|
||||||
|
uint16_t brightEnd = 12 + temp;
|
||||||
|
|
||||||
|
// --------------------------------------------------
|
||||||
|
// First 12 LEDs OFF
|
||||||
|
for (int i = 0; i < 12; i++) {
|
||||||
|
leds[i] = CRGB::Black;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gradient section (between solid colors)
|
||||||
|
for (int i = 18; i < 54; i++) {
|
||||||
|
|
||||||
|
uint8_t pos = map(i, 18, 53, 0, 255);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
FastLED.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- Known UIDs ----
|
||||||
|
|
||||||
|
// Right answers (4-byte UIDs)
|
||||||
|
const uint8_t RIGHT_UIDS[][4] = {
|
||||||
|
{0x4E, 0xBF, 0xCA, 0x06},
|
||||||
|
{0xF6, 0x4D, 0x1C, 0x06},
|
||||||
|
{0xA3, 0xBC, 0xCA, 0x06},
|
||||||
|
{0xC3, 0xDD, 0xCA, 0x06}
|
||||||
|
};
|
||||||
|
const uint8_t NUM_RIGHT_UIDS = 4;
|
||||||
|
|
||||||
|
// Wrong answers (7-byte UIDs)
|
||||||
|
const uint8_t WRONG_UIDS[][7] = {
|
||||||
|
{0x04, 0x97, 0xCF, 0x1F, 0x3F, 0x61, 0x80},
|
||||||
|
{0x04, 0x7C, 0xA9, 0x00, 0xA0, 0x61, 0x80},
|
||||||
|
{0x04, 0x6D, 0xC2, 0x2E, 0x5F, 0x61, 0x80},
|
||||||
|
{0x04, 0x22, 0x85, 0xFF, 0x9F, 0x61, 0x80}
|
||||||
|
};
|
||||||
|
const uint8_t NUM_WRONG_UIDS = 4;
|
||||||
|
|
||||||
|
|
||||||
|
bool compareUID(const uint8_t *uidA, const uint8_t *uidB, uint8_t length) {
|
||||||
|
for (uint8_t i = 0; i < length; i++) {
|
||||||
|
if (uidA[i] != uidB[i]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
UIDResult checkUID(const uint8_t *uid, uint8_t uidLength) {
|
||||||
|
|
||||||
|
// Check RIGHT UIDs (4 bytes)
|
||||||
|
if (uidLength == 4) {
|
||||||
|
for (uint8_t i = 0; i < NUM_RIGHT_UIDS; i++) {
|
||||||
|
if (compareUID(uid, RIGHT_UIDS[i], 4)) {
|
||||||
|
Serial.println("correct");
|
||||||
|
return UID_RIGHT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check WRONG UIDs (7 bytes)
|
||||||
|
if (uidLength == 7) {
|
||||||
|
for (uint8_t i = 0; i < NUM_WRONG_UIDS; i++) {
|
||||||
|
if (compareUID(uid, WRONG_UIDS[i], 7)) {
|
||||||
|
Serial.println("wrong");
|
||||||
|
return UID_WRONG;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Serial.println("unknown");
|
||||||
|
return UID_NONE;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user