[+] RGB!!
This commit is contained in:
+3
-3
@@ -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
|
||||
|
||||
@@ -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
|
||||
Submodule
+1
Submodule lib/FastLED added at 3a03742a09
+38
-9
@@ -3,10 +3,13 @@
|
||||
#include <Wire.h>
|
||||
#include <PN532_I2C.h>
|
||||
#include <PN532.h>
|
||||
#include <FastLED.h>
|
||||
#include <types.h>
|
||||
|
||||
#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<NEOPIXEL, GPIO_NUM_6>(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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user