PIR->WaveShield->Speakers +total noob

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
vanDude
 
Posts: 55
Joined: Tue Mar 08, 2011 11:37 am

Re: PIR->WaveShield->Speakers +total noob

Post by vanDude »

Hmm I understand what's going on in that article, but doing it effectively seems a little over my head.

So I'm thinking two things:

1.Try out your PIR. (BTW, how long of a recovery time do you think is possible for those? According to that article, mine is set at about 4.6 seconds.)

2. Go back to letting it play complete tracks before checking for HIGH again. For, if the sounds wanted are ambient type ones, they can be shorter and similar to each other, say thirty seconds, and hence if one leaves the range of the PIR in the middle of a track, it won't play obnoxiously long after leaving.

vanDude
 
Posts: 55
Joined: Tue Mar 08, 2011 11:37 am

Re: PIR->WaveShield->Speakers +total noob

Post by vanDude »

Or of course there is tweaking the code. Of course I don't know what exactly that entails.

Would it go something like whileplaying, digitalread, if low, delay, digitalread, if low, stop?

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: PIR->WaveShield->Speakers +total noob

Post by adafruit_support_bill »

1. I got my PIR's the same place you did. There is some variation in the actual modules over time.

2. That is always an option - if you can live with the drawbacks.

3. There are a few ways to approach a software solution. Ideally, you want to keep track of when the signal goes LOW and stop the wave if (and only if) it stays low for some arbitrary period of time.

One way to do this is as follows:

declare an 'unsigned long' time stamp at the global level.

In your playcomplete function:

If the signal is high - reset the time-stamp to zero.
if the signal is low:
* If the time stamp is zero - set the time stamp using millis()
* If the value of millis() minus the time stamp is greater than your time period - stop the wav.

vanDude
 
Posts: 55
Joined: Tue Mar 08, 2011 11:37 am

Re: PIR->WaveShield->Speakers +total noob

Post by vanDude »

Is part of the problem also that each time it resets it then gives a high signal because someone is still there, and then it therefore starts a new random track?

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: PIR->WaveShield->Speakers +total noob

Post by adafruit_support_bill »

You would put all that logic into the loop following the playfile(name);

You only exit the loop if:
The wave file is finished OR the signal has been LOW for some amount of time.

vanDude
 
Posts: 55
Joined: Tue Mar 08, 2011 11:37 am

Re: PIR->WaveShield->Speakers +total noob

Post by vanDude »

So a timestamp at the global level...is that like a definition that goes at the beginning of the whole sketch?

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: PIR->WaveShield->Speakers +total noob

Post by adafruit_support_bill »

Exactly. In the same place where you declare the FatReader and the WaveHC.

vanDude
 
Posts: 55
Joined: Tue Mar 08, 2011 11:37 am

Re: PIR->WaveShield->Speakers +total noob

Post by vanDude »

so the sketch might start like:

Code: Select all

#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"
unsigned long time;
?

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: PIR->WaveShield->Speakers +total noob

Post by adafruit_support_bill »

Yes.

vanDude
 
Posts: 55
Joined: Tue Mar 08, 2011 11:37 am

Re: PIR->WaveShield->Speakers +total noob

Post by vanDude »

Okay great. What vocabulary do I use to reset the time stamp? I'm not sure where to look in the references pages and the example for the Millis entry doesn't offer any hints.

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: PIR->WaveShield->Speakers +total noob

Post by adafruit_support_bill »

To reset:

time = 0;

To get the current time stamp:

time = millis();

vanDude
 
Posts: 55
Joined: Tue Mar 08, 2011 11:37 am

Re: PIR->WaveShield->Speakers +total noob

Post by vanDude »

So would the argument begin something like this?

Code: Select all

   case 1:
      playcomplete("BJOSNG.WAV");
if (digitalRead(14) == HIGH)  
{
time = 0;
}
if (digitalRead(14) == LOW)  
{
time = millis()
}

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: PIR->WaveShield->Speakers +total noob

Post by adafruit_support_bill »

That logic needs to be added to your playcomplete function as indicated in an earlier post:
In your playcomplete function:

If the signal is high - reset the time-stamp to zero.
if the signal is low:
* If the time stamp is zero - set the time stamp using millis()
* If the value of millis() minus the time stamp is greater than your time period - stop the wav.
You may want to change the name of the function too since it no longer unconditionaly plays the complete wav. maybe something like "playWhilePirSensed"

vanDude
 
Posts: 55
Joined: Tue Mar 08, 2011 11:37 am

Re: PIR->WaveShield->Speakers +total noob

Post by vanDude »

Right, sorry.

So would the playcomplete function begin this way?

Code: Select all

void playcomplete(char *name)
{
  // call our helper to find and play this name
  playfile(name);
  while (wave.isplaying)
  {
if (digitalRead(14) == HIGH)  
{
time = 0;
}
if (digitalRead(14) == LOW)  
{
time = millis()

User avatar
adafruit_support_bill
 
Posts: 88096
Joined: Sat Feb 07, 2009 10:11 am

Re: PIR->WaveShield->Speakers +total noob

Post by adafruit_support_bill »

OK up to the last line. When you detect a LOW signal, you need to check for two conditions:
if the signal is low:
* If the time stamp is zero - set the time stamp using millis()
* If the value of millis() minus the time stamp is greater than your time period - stop the wav
The first test detects the transition from HIGH to LOW and records the start time.
The second test monitors the elapsed time since the HIGH/LOW transition and stops the wav if it exceeds your time limit.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”