So beginnt es also ...

This commit is contained in:
Maira Bradler committed 2026-01-28 23:44:22 +01:00
commit 7768f8d72d
1 file changed
+196
+196
View File
@@ -0,0 +1,196 @@
//multiple RFID readers with SPI
/**************************************************************************/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>
// If using the breakout with SPI, define the pins for SPI communication.
#define PN532_SCK (2) //yellow
#define PN532_MOSI (3) //red
#define PN532_SS (4) //orange
#define PN532_MISO (5) //green
// Use this line for a breakout with a SPI connection:
Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, 4); //orange
Adafruit_PN532 nfc2(PN532_SCK, PN532_MISO, PN532_MOSI, 6); //brown
Adafruit_PN532 nfc3(PN532_SCK, PN532_MISO, PN532_MOSI, 7); //purple
//LED strip baseline
/**************************************************************************/
#include <FastLED.h>
#define LED_PIN 8
#define NUM_LEDS 60
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
// Base colors (pure RGB, no green component)
CRGB blue = CRGB(0, 0, 180);
CRGB red = CRGB(180, 0, 0);
// Brightness levels
const uint8_t DIM_SCALE = 2;
const uint8_t BRIGHT_SCALE = 100;
void setupNFC(Adafruit_PN532 nfc){
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board on");
while (1); // halt
}
// Got ok data, print it out!
Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
// Set the max number of retry attempts to read from a card
// This prevents us from waiting forever for a card, which is
// the default behaviour of the PN532.
nfc.setPassiveActivationRetries(0xFF);
Serial.println("Waiting for an ISO14443A card");
}
/**************************************************************************/
void setup(void) {
//LED set-up
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(255); // Control brightness manually
Serial.begin(115200);
while (!Serial) delay(10); // for Leonardo/Micro/Zero
Serial.println("Hello!");
setupNFC(nfc);
setupNFC(nfc2);
setupNFC(nfc3);
}
boolean getCardID(Adafruit_PN532 nfc, uint8_t *uid ){
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--------------
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength, 100);
if (success) {
return true;
}
return false;
}
/**************************************************************************/
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
//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)
//Reader 01--------------
success1 = getCardID(nfc, &uid1[0]);
success2 = getCardID(nfc2, &uid2[0]);
success3 = getCardID(nfc3, &uid3[0]);
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("");
}
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("");
}
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);
}
Serial.println("");
}
}void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}