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.
PIR->WaveShield->Speakers +total noob
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
-
- Posts: 55
- Joined: Tue Mar 08, 2011 11:37 am
Re: PIR->WaveShield->Speakers +total noob
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?
Would it go something like whileplaying, digitalread, if low, delay, digitalread, if low, stop?
- adafruit_support_bill
- Posts: 88096
- Joined: Sat Feb 07, 2009 10:11 am
Re: PIR->WaveShield->Speakers +total noob
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.
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.
-
- Posts: 55
- Joined: Tue Mar 08, 2011 11:37 am
Re: PIR->WaveShield->Speakers +total noob
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?
- adafruit_support_bill
- Posts: 88096
- Joined: Sat Feb 07, 2009 10:11 am
Re: PIR->WaveShield->Speakers +total noob
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.
You only exit the loop if:
The wave file is finished OR the signal has been LOW for some amount of time.
-
- Posts: 55
- Joined: Tue Mar 08, 2011 11:37 am
Re: PIR->WaveShield->Speakers +total noob
So a timestamp at the global level...is that like a definition that goes at the beginning of the whole sketch?
- adafruit_support_bill
- Posts: 88096
- Joined: Sat Feb 07, 2009 10:11 am
Re: PIR->WaveShield->Speakers +total noob
Exactly. In the same place where you declare the FatReader and the WaveHC.
-
- Posts: 55
- Joined: Tue Mar 08, 2011 11:37 am
Re: PIR->WaveShield->Speakers +total noob
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;
- adafruit_support_bill
- Posts: 88096
- Joined: Sat Feb 07, 2009 10:11 am
-
- Posts: 55
- Joined: Tue Mar 08, 2011 11:37 am
Re: PIR->WaveShield->Speakers +total noob
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.
- adafruit_support_bill
- Posts: 88096
- Joined: Sat Feb 07, 2009 10:11 am
Re: PIR->WaveShield->Speakers +total noob
To reset:
time = 0;
To get the current time stamp:
time = millis();
time = 0;
To get the current time stamp:
time = millis();
-
- Posts: 55
- Joined: Tue Mar 08, 2011 11:37 am
Re: PIR->WaveShield->Speakers +total noob
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()
}
- adafruit_support_bill
- Posts: 88096
- Joined: Sat Feb 07, 2009 10:11 am
Re: PIR->WaveShield->Speakers +total noob
That logic needs to be added to your playcomplete function as indicated in an earlier post:
You may want to change the name of the function too since it no longer unconditionaly plays the complete wav. maybe something like "playWhilePirSensed"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.
-
- Posts: 55
- Joined: Tue Mar 08, 2011 11:37 am
Re: PIR->WaveShield->Speakers +total noob
Right, sorry.
So would the playcomplete function begin this way?
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()
- adafruit_support_bill
- Posts: 88096
- Joined: Sat Feb 07, 2009 10:11 am
Re: PIR->WaveShield->Speakers +total noob
OK up to the last line. When you detect a LOW signal, you need to check for two conditions:
The second test monitors the elapsed time since the HIGH/LOW transition and stops the wav if it exceeds your time limit.
The first test detects the transition from HIGH to LOW and records the start time.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 second test monitors the elapsed time since the HIGH/LOW transition and stops the wav if it exceeds your time limit.
Please be positive and constructive with your questions and comments.