Hi all,
Some of you have already helped me with the beginning of this project which I am thankful for but I have not been completely successful yet.
Trying to create a puzzle whereby scanning 10 different RFID tags will progressively increase the number of LEDs on a 32 x 8 LED matrix. This is for an escape room puzzle and will show a code after the 10 tags have all been scanned.
So what I have attempted to do is create a 2D array to cover the specific LED progressions and when a tag is scanned that has NOT been scanned before, go to the next stage of LEDs.
I've tried to use a variable called cellMutationStage to indicate the stage at which the LEDs should show depending on how many tags have been scanned.
I feel like I'm not a million miles away but if it doesn't work it doesn't work. I am currently not seeing any LEDs upon scanning where I did have a version where it showed the specific LEDs, though I couldn't get it to do the next stage.
Hard work this coding stuff, many thanks for any help!
Ben
#include <SPI.h>
#include <MFRC522.h>
#include <FastLED.h>
#include <Wire.h>
//pin declarations
#define LED_PIN 4
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
//declaring an RFID read instance
MFRC522 mfrc522(SS_PIN, RST_PIN);
//For the LED Matrix
#define COLOR_ORDER GRB
#define CHIPSET WS2811
#define cellColour 100,0,0 //RGB colour numbers, currently red
#define BRIGHTNESS 50
const uint8_t kMatrixWidth = 32;
const uint8_t kMatrixHeight = 8;
#define NUM_LEDS (kMatrixWidth * kMatrixHeight) //Number of LEDs is the height x the width
CRGB leds_plus_safety_pixel[ NUM_LEDS + 1]; //Don't ask, it works and if I change it it doesnt
CRGB* const leds( leds_plus_safety_pixel + 1);
//Arrays for the LED matrix stages and the size of each
int ledArray[2][14] = {
{25,28,106,110,125,146,164,169,180,227},
{25,28,106,110,125,146,164,169,180,227,46,116,173,234}
};
//RFID tags and their IDs
const int numTags = 10;
const String IDs[] = {"D3 54 07 0C", "43 0D 61 0D", "53 ED 08 0C", "13 A1 24 0C", "03 B3 1A 0C", "53 60 6F 0D", "C3 B0 18 0C", "63 04 27 0C", "13 DC 7B 0D", "93 A7 10 0C" };
String tagIDTracker[numTags]{}; //empty array to add the scanned IDs into
//variable for stage progression
int cellMutationStage = 0;
void setup() {
//Setups for the RFID reader, Serial monitor and the LED matrix
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness( BRIGHTNESS );
}
void loop() {
//Standard RFID reader code section
String readRFID = "";
// If the sensor detects a tag and is able to read it
if(mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()) {
// Extract the ID from the tag
readRFID = dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
//If the tag that has been read is not in the tagIDTracker array, meaning it's not been scanned, then add 1 to the cellMutationStage
//variable and then add the new tag to the tagIDTracker array so it cannot be scanned again. Print the cellMutationVariable so we can see if it's progressing
if(readRFID != tagIDTracker[numTags]){
//Update the cellMutationStage variable to go to the next stage of the LED lights
cellMutationStage++;
Serial.print(cellMutationStage);
// Add the newly scanned tag to the empty array
tagIDTracker[numTags] = readRFID;
}
//first if statement for the lights, if cellMutationStage variable is on 0 (meaning nothing has been scanned) then show the first array of LEDs
if (cellMutationStage == 0) {
for(int i=0; i<10; i++)
{
leds[ledArray[0][i]].setRGB(cellColour);
delay(100);
FastLED.setBrightness( BRIGHTNESS );
FastLED.show();
}}}}
//heplper function to get the byte info from the RFID reader - works fine atm
String dump_byte_array(byte *buffer, byte bufferSize) {
String read_rfid = "";
for (byte i=0; i<bufferSize; i++) {
read_rfid = read_rfid + String(buffer[i], HEX);
}
return read_rfid;
}
type or paste code here