From c96195c7993a3bf9f62f19734aaebdb6d512c5ce Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Sat, 25 Nov 2023 04:36:03 -0500 Subject: [PATCH] [+] RGB!! --- .gitmodules | 6 +++--- include/types.h | 15 +++++++++++++++ lib/FastLED | 1 + src/main.cpp | 47 ++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 include/types.h create mode 160000 lib/FastLED diff --git a/.gitmodules b/.gitmodules index 8c0f673..8328524 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "lib/PN532"] - path = lib/PN532-repo - url = https://github.com/Seeed-Studio/PN532/ +[submodule "lib/FastLED"] + path = lib/FastLED + url = https://github.com/FastLED/FastLED diff --git a/include/types.h b/include/types.h new file mode 100644 index 0000000..a74aa1c --- /dev/null +++ b/include/types.h @@ -0,0 +1,15 @@ +#ifndef TYPES_H +#define TYPES_H + +#define u8 uint8_t +#define u16 uint16_t +#define u32 uint32_t + +#define s8 int8_t +#define s16 int16_t +#define s32 int32_t + +#define f32 float +#define f64 double + +#endif //TYPES_H diff --git a/lib/FastLED b/lib/FastLED new file mode 160000 index 0000000..3a03742 --- /dev/null +++ b/lib/FastLED @@ -0,0 +1 @@ +Subproject commit 3a03742a09aeb219a065954d7f85be9cdd2582f0 diff --git a/src/main.cpp b/src/main.cpp index 2d0ccf8..ef11adf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,10 +3,13 @@ #include #include #include +#include +#include -#define u8 uint8_t -#define u16 uint16_t -#define u32 uint32_t +constexpr u8 NUM_LEDS = 7; +constexpr u8 BR_DIM = 8; +constexpr u8 BR_BRIGHT = 14; +CRGB leds[NUM_LEDS]; PN532_I2C pn532i2c(Wire); PN532 nfc(pn532i2c); @@ -18,7 +21,7 @@ u32 prevTime; void setup() { // Add initial delay to allow the serial monitor to catch up - delay(1000); + delay(500); // Initialize serial port USBSerial.begin(115200); @@ -27,6 +30,10 @@ void setup() // Initialize I2C communication Wire.setPins(GPIO_NUM_4, GPIO_NUM_5); + // Initialize the LED + CFastLED::addLeds(leds, NUM_LEDS); + FastLED.setBrightness(BR_DIM); + // Find the PN532 NFC module nfc.begin(); u32 versiondata; @@ -50,7 +57,25 @@ void setup() nfc.SAMConfig(); // Clear the IDm buffer - memset(prevIDm, 0, 8); + memset(prevIDm, 0, UID_LENGTH); +} + +void led_animation() +{ + FastLED.setBrightness(BR_BRIGHT); + CRGB colors[] = {CRGB::LimeGreen, CRGB::Black, CRGB::Gold, CRGB::Black}; + + for (const auto color : colors) + { + for (u8 i = 1; i < NUM_LEDS; i++) + { + leds[i] = color; + FastLED.show(); + delay(35); + } + } + + FastLED.setBrightness(BR_DIM); } void foundCard(const u8* uid, const u8 len, const char* cardType) @@ -68,6 +93,8 @@ void foundCard(const u8* uid, const u8 len, const char* cardType) USBSerial.print(uid[i], HEX); USBSerial.println(""); + led_animation(); + memcpy(prevIDm, uid, UID_LENGTH); prevTime = millis(); } @@ -80,13 +107,15 @@ void loop() // Wait for an FeliCa type cards. // When one is found, some basic information such as IDm, PMm, and System Code are retrieved. - USBSerial.print("F"); - if (nfc.felica_Polling(0xFFFF, 0x00, idm, pmm, &systemCode, 5)) + leds[0] = CRGB::BlueViolet; + FastLED.show(); + if (nfc.felica_Polling(0xFFFF, 0x00, idm, pmm, &systemCode, 5) == 1) foundCard(idm, UID_LENGTH, "FeliCa"); // Wait for an ISO14443A type cards (MIFARE, etc.). When one is found u8 uidLength; - USBSerial.print("M"); - if (nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, idm, &uidLength, 5)) + leds[0] = CRGB::OrangeRed; + FastLED.show(); + if (nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, idm, &uidLength, 5) == 1) foundCard(idm, uidLength, "ISO14443A"); }