This is my best shoot with the whistle. Actually i'm working in a whistling mirror for a girl. i want to plug it in a girl's toilet and when they goes to see herself in front of the mirror for a while. the mirror whistle for her.
int buzz = 12;
int PIR = 2;
int senal = 0;
int tiempo;
void silba()
{
int i;
int x;
for ( i=200; i>100; i--)
{
for ( x=0; x<5; x++)
{
digitalWrite (12,HIGH);
delayMicroseconds (i);
digitalWrite (12,LOW);
delayMicroseconds (i);
}
}
delay(500);
for ( i=300; i>100; i--)
{
for ( x=0; x<4; x++)
{
digitalWrite (12,HIGH);
delayMicroseconds (i);
digitalWrite (12,LOW);
delayMicroseconds (i);
}
}
for (i=100; i<300; i++)
{
digitalWrite (12,HIGH);
delayMicroseconds(i);
digitalWrite(12,LOW);
delayMicroseconds(i);
}
}
void setup ()
{
Serial.begin(9600);
pinMode(12,OUTPUT);
}
void loop ()
{
senal= analogRead(PIR);
if(senal>500)
{
tiempo ++;
Serial.println("Presencia detectada en:");
Serial.println(tiempo);
}
if( tiempo > 11)
{
silba();
for(int x = 0 ; x < 1;x++)
{
delay(12000);
}
tiempo =0;
}
delay(1000);
}