Pages: [1]   Go Down
Author Topic: i want to replay the sound  (Read 1817 times)
0 Members and 1 Guest are viewing this topic.
egypt
Offline Offline
Newbie
*
Karma: 0
Posts: 29
i 'm biomedical engineer and love arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

this code is for a project used the RFID & SD cards to made an simple audio play for one id

i use tags with ID's

it's work good

but for one time not work as a loop!!!!

when i near the rfid card to the reader it's work a one of the play samples

but for one time >>>>>> and i need to replay  the arduino

#include <PN532.h>
#include <SPI.h>
#include <SimpleSDAudio.h>
#define PN532_CS 10
PN532 nfc(PN532_CS);
#define NFC_DEMO_DEBUG 1
void setup() {
#ifdef NFC_DEMO_DEBUG
#endif
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
#ifdef NFC_DEMO_DEBUG

#endif
while (1); // halt
}
#ifdef NFC_DEMO_DEBUG

#endif
nfc.SAMConfig();

}
void loop(void)
{

uint32_t id;
id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);

if (id != 0)
{
#ifdef NFC_DEMO_DEBUG
Serial.print("Read card #");
Serial.println(id);
if(id==4251492471)
{
if (SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO))
{
if(SdPlay.setFile("12.afm"))
{
SdPlay.play();
while(!SdPlay.isStopped())
{
SdPlay.worker();

}
}
}
}
}

#endif
}
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 506
Posts: 19120
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How to use this forum


Code tags, please.
Logged


egypt
Offline Offline
Newbie
*
Karma: 0
Posts: 29
i 'm biomedical engineer and love arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

sorry what you mean by tage ??
Logged

Offline Offline
Jr. Member
**
Karma: 6
Posts: 75
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
please use the line if (SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO)) only once at setup.
Logged

egypt
Offline Offline
Newbie
*
Karma: 0
Posts: 29
i 'm biomedical engineer and love arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

ok>>>>> but shat about ""if""?????????
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 506
Posts: 19120
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What about the code tags? And please use the auto-format tool in the IDE. This sort of stuff is impossible to follow:

Code:
}
}
}
}
}

#endif
}

Quote
sorry what you mean by tage ??

Do you mean "tags"? Read this: How to use this forum

There is a pretty clear screen-shot showing what I mean.
Logged


egypt
Offline Offline
Newbie
*
Karma: 0
Posts: 29
i 'm biomedical engineer and love arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#include <PN532.h>
#include <SPI.h>
#include <SimpleSDAudio.h>
#define PN532_CS 10
PN532 nfc(PN532_CS);
#define NFC_DEMO_DEBUG 1
void setup() {
#ifdef NFC_DEMO_DEBUG
#endif
nfc.begin();
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
#ifdef NFC_DEMO_DEBUG

#endif
while (1); // halt
}
#ifdef NFC_DEMO_DEBUG

#endif
nfc.SAMConfig();

}
void loop(void)
{

uint32_t id;
id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);

if (id != 0)
{
#ifdef NFC_DEMO_DEBUG
Serial.print("Read card #");
Serial.println(id);
if(id==4251492471)
{
if (SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO))
{
if(SdPlay.setFile("12.afm"))
{
SdPlay.play();
while(!SdPlay.isStopped())
{
SdPlay.worker();

}
}
}
}
}

#endif
}
Logged

egypt
Offline Offline
Newbie
*
Karma: 0
Posts: 29
i 'm biomedical engineer and love arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

thanx ........ this is the code
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 506
Posts: 19120
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

And please use the auto-format tool in the IDE.

^^^^

This.
Logged


egypt
Offline Offline
Newbie
*
Karma: 0
Posts: 29
i 'm biomedical engineer and love arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

ok now help me plz  smiley-cool
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 506
Posts: 19120
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here, let me format it for you:

Code:
#include <PN532.h>
#include <SPI.h>
#include <SimpleSDAudio.h>
#define PN532_CS 10
PN532 nfc(PN532_CS);
#define NFC_DEMO_DEBUG 1
void setup() {
#ifdef NFC_DEMO_DEBUG
#endif
  nfc.begin();
  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
#ifdef NFC_DEMO_DEBUG

#endif
    while (1); // halt
  }
#ifdef NFC_DEMO_DEBUG

#endif
  nfc.SAMConfig();

}
void loop(void)
{

  uint32_t id;
  id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);

  if (id != 0)
  {
#ifdef NFC_DEMO_DEBUG
    Serial.print("Read card #");
    Serial.println(id);
    if(id==4251492471)
    {
      if (SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO))
      {
        if(SdPlay.setFile("12.afm"))
        {
          SdPlay.play();
          while(!SdPlay.isStopped())
          {
            SdPlay.worker();

          }
        }
      }
    }
  }

#endif
}

Logged


Global Moderator
Offline Offline
Brattain Member
*****
Karma: 506
Posts: 19120
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This is confusing:

Code:
#ifdef NFC_DEMO_DEBUG
#endif

What's the point?

I'll get rid of all the #ifdef:

Code:
#include <PN532.h>
#include <SPI.h>
#include <SimpleSDAudio.h>
#define PN532_CS 10
PN532 nfc(PN532_CS);

void setup()
{
  nfc.begin();
  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata)
  {
    while (1); // halt
  }
  nfc.SAMConfig();

} // end of setup

void loop(void)
{
  uint32_t id;
  id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);

  if (id != 0)
  {
    Serial.print("Read card #");
    Serial.println(id);
    if(id==4251492471)
    {
      if (SdPlay.init(SSDA_MODE_FULLRATE | SSDA_MODE_MONO))
      {
        if(SdPlay.setFile("12.afm"))
        {
          SdPlay.play();
          while(!SdPlay.isStopped())
          {
            SdPlay.worker();
          }
        }
      }
    }
  }
}


You have this:

Code:
    Serial.print("Read card #");
    Serial.println(id);

But no Serial.begin.

OK, now we can read the code, what is the problem exactly?

I don't understand this:

Quote
it's work good

but for one time not work as a loop!!!!
Logged


egypt
Offline Offline
Newbie
*
Karma: 0
Posts: 29
i 'm biomedical engineer and love arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

i mean that >>> the program should made an audio output every time i near the rfid card
but in this code it's search for the card successfully and made an audio output successfully but when the audio ended it's doesn't search about the card again !!!! so i need to made the program to search again without restarting the board from the button
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 506
Posts: 19120
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

RFID card readers typically return a single response for one card, and then don't "notice" that card until it moves away and comes back.
Logged


Pages: [1]   Go Up
Jump to: