byte check_switches()
{
if (digitalRead(14) == HIGH) // check for high signal on pin 14 (analog 0)
{
return Random(1,6);
}
if (wave.isplaying) // stop it
{
wave.stop();
}
return 0;
}
void playcomplete(char *name) {
// call our helper to find and play this name
playfile(name);
while (wave.isplaying) {
byte check_switches()
{
if (digitalRead(14) == LOW) // check for high signal on pin 14 (analog 0)
{
wave.stop();
}
return 0;
}
}
// now its done playing
}
void playcomplete(char *name) {
// call our helper to find and play this name
playfile(name);
while (wave.isplaying) {
byte check_switches()
{
if (digitalRead(14) == LOW) // check for high signal on pin 14 (analog 0)
{
wave.stop();
}
return;
}
}
// now its done playing
}
but I am getting this:
sketch_mar14a.cpp: In function 'void playcomplete(char*)':
sketch_mar14a:141: error: a function-definition is not allowed here before '{' token
sketch_mar14a:170: error: expected `}' at end of input
sketch_mar14a:170: error: expected `}' at end of input
Your brackets need to be 'balanced'. It is easier to see if you keep the indenting consistent.
The error was the 'byte' before the call to check_switches. But that call was redundant because you are also checking the input directly with your digitalRead().
A simplified version is below:
void playcomplete(char *name)
{
// call our helper to find and play this name
playfile(name);
while (wave.isplaying)
{
if (digitalRead(14) == LOW) // check for high signal on pin 14 (analog 0)
{
wave.stop(); // stop and return if no person detected
return;
}
}
// now its done playing
}
Okay I see thanks very much arduwino. Anyway, success!!
So, the way it is behaving now will require a little modification, because if someone stops moving for just a moment it shuts off and then starts again when someone moves again. This is exactly what it's programmed to do, but the effect is rather choppy and jumpy, so I suppose I should insert a delay in there somewhere, say of about 30 seconds. Perhaps, if it does the check every 20 seconds for LOW, it might mitigate that effect. Can I slip that in before the digital read after while (wave.isplaying)?
The PIR module has an adjustable timeout (on the ones I have here, it is a small trim-pot on the circuit board). You may be able to adjust that for a long enough delay to solve your problem.
In code, it would be a little trickier than what you propose. You want to start timing when the signal goes low, and test it again before deciding to stop the wav.