I want Different sound to Rfid when Led animation end

LED = Led strip (ws2812b)
RFID = MIRC522
Wav Player = Adafruit FX sound board

  • Echo sensor (for Led animation on / off)

potetiometer * 4 = HSV + animation Speed

Led animation = Raindrop animation
(it is Scanner animation by : Scanner | Multi-tasking the Arduino - Part 3 | Adafruit Learning System)

I want playing different sound when Led animation end.

#1 https://youtu.be/zyxYEuxIXqo
#2 https://youtu.be/RcnocHZrH-0

It was doing half
but sound working once two animation cycle

lightspeed.ino (8.55 KB)

Please read this post first: How to use this forum

I do not understand what you are asking.

What is it you want to do?

What does not work?

What have you tried to fix it?

oh I’m sorry
I want solve a problem

My project

  1. Playing LED Animation

  2. If Led light on pixel end = Rfid Check

  3. If Rfid ID HEX = AA AA AA AA = FX Sound Board playing 01.WAV
    3-2. If Rfid ID HEX = BB BB BB BB = FX Sound Board playing 02.WAV

Problem is sound.
It does not work once in two times
It will be easy to understand when you look at the link
( fxsound - YouTube )

Can you please help me with my code?
I think this is the problem.

void Increment()
{
      
SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);
Adafruit_Soundboard sfx = Adafruit_Soundboard(&ss, NULL, SFX_RST);
ss.begin(9600);
String content= "";
byte letter;

        if (Direction == FORWARD)
        {
           Index++;
           if (Index >= TotalSteps)
            {
                Index = 0;
                
                  if ( ! mfrc522.PICC_IsNewCardPresent()) 
                  {
                         return;
                  }
                  if ( ! mfrc522.PICC_ReadCardSerial()) 
                  {
                         return;
                  }
                  for (byte i = 0; i < mfrc522.uid.size; i++) 
                    {
                        Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
                        Serial.print(mfrc522.uid.uidByte[i], HEX);
                        content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
                        content.concat(String(mfrc522.uid.uidByte[i], HEX));
                    }
                    Serial.println();
                    Serial.print("Message : ");
                    content.toUpperCase();
                     if (content.substring(1) == "72 7E 10 85") //change here the UID of the card/cards that you want to give access
                      {
                          Serial.println("Authorized access");
                          Serial.println();
                          sfx.playTrack("DROPING0WAV");
                        
                      }
                       else if (content.substring(1) == "64 C5 E6 AB") //change here the UID of the card/cards that you want to give access
                      {
                          Serial.println("Authorized access");
                          Serial.println();
                          sfx.playTrack("DROPING1WAV");
                        
                      } 
  
                        else if (content.substring(1) == "ED 9A DE 2B") //change here the UID of the card/cards that you want to give access
                      {
                          Serial.println("Authorized access");
                          Serial.println();
                          sfx.playTrack("DROPING2WAV");
                        
                       }
                        else if (content.substring(1) == "AB 76 E2 2B") //change here the UID of the card/cards that you want to give access
                      {
                          Serial.println("Authorized access");
                          Serial.println();
                          sfx.playTrack("DROPING3WAV");
                        
                      }
                }
                    }
                }

Well we actually want to see all of the code, but I suspect what is happening is the WS2812 libiary is disabling the interrupts when sending out the data to the LED strip. They all do this in order to get the tightly timed signals these chips require.

This is then causing the RFID card reader to only read in a section of the RFID code some of the time.

Possible solutions are:-
to use the Dot Star type LED strip as they do not require tight timing, and sending data can be interrupted.

Use an other processor like an ATtiny to send the data to the strip and communicate with this device through the SPI pins, or use a bit banged SPI interface using any pins.

SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);
Adafruit_Soundboard sfx = Adafruit_Soundboard(&ss, NULL, SFX_RST);
ss.begin(9600);

All this should be in the start up function not done every time you want to make a reading from the RFID reader.

Thanks for all advice
But now I do not have ATtiny, so I can not experiment.

Could you tell me if my code is wrong?
It is all my code

I think that

  1. i = Index

  2. If Index == Totalsteps
    2-2 . Index = 0;

  3. If Index = 0
    3-2. Rfid Check

  4. Rfid Hex : AA AA AA AA = FX Sound board Playing 01.wav

  5. Rfid Hex : BB BB BB BB = FX Sound board Playing 02.wav

Led

#include <Adafruit_NeoPixel.h>
#include <SoftwareSerial.h>
#include <SPI.h>
#include <MFRC522.h>
#include "Adafruit_Soundboard.h"

#define SS_PIN 10
#define RST_PIN 9
#define SFX_TX 3
#define SFX_RX 2
#define SFX_RST 4

SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);
Adafruit_Soundboard sfx = Adafruit_Soundboard(&ss, NULL, SFX_RST);
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.


// Pattern types supported:
enum  pattern { NONE, SCANNER, FADE };
// Patern directions supported:
enum  direction { FORWARD, REVERSE };

// NeoPattern Class - derived from the Adafruit_NeoPixel class
class NeoPatterns : public Adafruit_NeoPixel
{
    public:

    // Member Variables:  
    pattern  ActivePattern;  // which pattern is running
    direction Direction;     // direction to run the pattern
    
    unsigned long Interval;   // milliseconds between updates
    unsigned long lastUpdate; // last update of position
    
    uint32_t Color1, Color2;  // What colors are in use
    uint16_t TotalSteps;  // total number of steps in the pattern
    uint16_t Index;  // current step within the pattern
    
    void (*OnComplete)();  // Callback on completion of pattern
    
    String content= "";
    byte letter;
    
    // Constructor - calls base-class constructor to initialize strip
    NeoPatterns(uint16_t pixels, uint8_t pin, uint8_t type())
    :Adafruit_NeoPixel(pixels, pin, type)
    {
    }
    
    // Update the pattern
    void Update()
    {
      
        if((millis() - lastUpdate) > Interval) // time to update
        { int value4 = analogRead(A3); // read the value from the first potentiometer
          byte byte4 = map(value4, 0, 1023, 0, 255); // scale the value of first potentiometer
            lastUpdate = millis();
            switch(ActivePattern)
            {
                case SCANNER:
                    ScannerUpdate(byte4);
                    break;
                case FADE:
                    FadeUpdate();
                    break;
                default:
                    break;
            }
        }
    }
  
    // Increment the Index and reset at the end
       void Increment()
    {
String content= "";
byte letter;

        if (Direction == FORWARD)
        {
           Index++;
           if (Index == TotalSteps)
            {
                Index = 0;
                
                  if ( ! mfrc522.PICC_IsNewCardPresent()) 
                  {
                         return;
                  }
                  if ( ! mfrc522.PICC_ReadCardSerial()) 
                  {
                         return;
                  }
                  for (byte i = 0; i < mfrc522.uid.size; i++) 
                    {
                        Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
                        Serial.print(mfrc522.uid.uidByte[i], HEX);
                        content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
                        content.concat(String(mfrc522.uid.uidByte[i], HEX));
                    }
                    content.toUpperCase();
                     if (content.substring(1) == "72 7E 10 85") //change here the UID of the card/cards that you want to give access
                      {
                          Serial.println("Authorized access");
                          Serial.println();
                          sfx.playTrack("DROPING0WAV");
                          return;
                      }
                       else if (content.substring(1) == "64 C5 E6 AB") //change here the UID of the card/cards that you want to give access
                      {
                          Serial.println("Authorized access");
                          Serial.println();
                          sfx.playTrack("DROPING1WAV");
                          return;
                      } 
  
                        else if (content.substring(1) == "ED 9A DE 2B") //change here the UID of the card/cards that you want to give access
                      {
                          Serial.println("Authorized access");
                          Serial.println();
                          sfx.playTrack("DROPING2WAV");
                          return;
                       }
                        else if (content.substring(1) == "AB 76 E2 2B") //change here the UID of the card/cards that you want to give access
                      {
                          Serial.println("Authorized access");
                          Serial.println();
                          sfx.playTrack("DROPING3WAV");
                          return;
                      }
                }
                    }
                }
  
    void Scanner(uint32_t color1)
    {
        ActivePattern = SCANNER;
        TotalSteps = (numPixels());
        Color1 = color1;
        Index = 0;
    }

    // Update the Scanner Pattern
    void ScannerUpdate(uint8_t interval)
    {
Interval = interval;
int trig = 6;
int echo = 5;

long duration;
int distance;

  digitalWrite(trig, LOW);
  delayMicroseconds(2);
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  
  duration = pulseIn(echo, HIGH);
  distance = duration * 0.034 / 2;
  
        for (int i = 0; i < numPixels(); i++)
        {
              if (distance > 10)  // Scan Pixel to the right
  {
                  setPixelColorHsv(i,0,0,0);
  }

            if (10 > distance)  // Scan Pixel to the right
            {
              if (i == Index)
              {
                 setPixelColorHsv(i, analogRead(A0),analogRead(A1),analogRead(A2));
            }
             else // Fading tail
            {
                 setPixelColor(i, DimColor(getPixelColor(i)));
            }
            }
}
        Increment();
        show();
        
    }
    
    // Initialize for a Fade
    void Fade(uint32_t color1, uint32_t color2, uint16_t steps, uint8_t interval, direction dir = FORWARD)
    {
        ActivePattern = FADE;
        Interval = interval;
        TotalSteps = steps;
        Color1 = color1;
        Color2 = color2;
        Index = 0;
        Direction = dir;
    }
    
    // Update the Fade Pattern
    void FadeUpdate()
    {
        // Calculate linear interpolation between Color1 and Color2
        // Optimise order of operations to minimize truncation error
        uint8_t red = ((Red(Color1) * (TotalSteps - Index)) + (Red(Color2) * Index)) / TotalSteps;
        uint8_t green = ((Green(Color1) * (TotalSteps - Index)) + (Green(Color2) * Index)) / TotalSteps;
        uint8_t blue = ((Blue(Color1) * (TotalSteps - Index)) + (Blue(Color2) * Index)) / TotalSteps;
        
        ColorSet(Color(red, green, blue));
        show();
        Increment();
    }
   
    // Calculate 50% dimmed version of a color (used by ScannerUpdate)
    uint32_t DimColor(uint32_t color)
    {
        // Shift R, G and B components one bit to the right
        uint32_t dimColor = Color(Red(color) >> 1, Green(color) >> 1, Blue(color) >> 1);
        return dimColor;
    }

    // Set all pixels to a color (synchronously)
    void ColorSet(uint32_t color)
    {
        for (int i = 0; i < numPixels(); i++)
        {
            setPixelColor(i, color);
        }
        show();
    }

    // Returns the Red component of a 32-bit color
    uint8_t Red(uint32_t color)
    {
        return (color >> 16) & 0xFF;
    }

    // Returns the Green component of a 32-bit color
    uint8_t Green(uint32_t color)
    {
        return (color >> 8) & 0xFF;
    }

    // Returns the Blue component of a 32-bit color
    uint8_t Blue(uint32_t color)
    {
        return color & 0xFF;
    }
};


NeoPatterns Stick(69, 7, NEO_GRB + NEO_KHZ800);

unsigned int trig = 6;
unsigned int echo = 5;


    
void setup()
{
  Serial.begin(9600);
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
  
  pinMode(trig,OUTPUT);
  pinMode(echo,INPUT);
  ss.begin(9600);
  Stick.begin();
  Stick.Scanner(Stick.Color(0, 0, 0));
  
}

// Main loop
void loop()
{
  ss.listen();
  Stick.Update();
}

Could you tell me if my code is wrong?

Well it is not the best written code and you include that very very poor example from the MFRC522 libiary.
However it does work sometimes and in this situation where we know exactly what the problem is then I don't think you are going to solve by rearranging you Arduino code.

I have pointed out the fundamental problem you have, and suggested ways of overcoming them. I don't see what more I can do.