Tap and Playback
Counts the number of times the speaker is tapped and reports back the number of taps with a series of tones. Works best with larger speakers. Have Fun!
--------------------------- Copy Code Below
/*
Reports a tone the number of times a speaker is tapped
Speaker is connected between A0 and ground
Don't push the speaker too hard!!
Add a potentiometer for setting the threshold pulse from speaker
A piezo disk can be used with a 10k resistor in parallel with the disk
the threshold signal must be adjusted for a disk and you can tape
it to a table or box to help it sound louder
Created by Dorian McIntire - dorianmc@gmail.com
*/
byte tapCount = 0;
long int tapTime = millis();
void setup()
{
}
void loop()
{
int sensorValue = analogRead(A0);
if(sensorValue > 5) //detect a tap
{
delay(50);
tapCount = tapCount + 1; //increment tap count
tapTime = millis(); //record current system time
} //end if 1
pinMode(A0,OUTPUT);
if (tapTime < (millis() - 400)) //if more than 0.4 seconds have elapsed since last tap
{
for(int x=0; x < tapCount; x++)
{
tone(A0,1500);
delay(200);
noTone(A0);
delay(200);
}//end for
pinMode(A0,INPUT);
tapCount = 0;
}//end if 2
delay(5); // delay in between reads for stability
} // end loop
--------------------------- Copy Code Above
Going Further
1. Use to make a combination lock choose the number of taps for a basic lock or reprogram to enter as many digits as possible for your combination
2. Use as an input device to select a menu option
3. Build a calculator using the speaker to input a number
I loved It sir!
ReplyDelete