task main(){
int time[20]; //Take a maximum of 20 samples
long t0;
int i=0;
int x=1;
SetSensorSound(IN_1); /* Setup port 1 as sound sensor */
/* Loop while the difference between the current timer and the initial timer is less than 5 seconds */
while ((CurrentTick()-t0) < 5000) {
if(Sensor(IN_1) < 30) { /* If the sensors hears a loud sound, record the timer value */
i++;
until(Sensor(IN_1) < 29); /* Wait until that sound has dissapated before looking for the next */
}
}
/* Start taps */
OnFwd(OUT_A, 100); Wait(75);
OnRev(OUT_A, 100); Wait(75);
Off(OUT_A);
for(x=1;x<20;x++) {
if(time[x]==0){ /* If the difference is 0, that means that there are no more claps recorded */
}
/* Wait for the time difference between each clap don’t forget that tap also takes up a certain amount of time */
Wait( time[x]-time[x-1]-150);
OnFwd(OUT_A, 100); Wait(75);
OnRev(OUT_A, 100); Wait(75);
Off(OUT_A);
}
Wait(1000);
}
6 Comments
Comments are closed.
I don't see why you couldn't do the same with the EV3 and NXT Sound sensors. I need to add it to my to-do list!
Very cool program!
Is it possible to get similar results in mindstorms with an EV3 (with NXT microphone sensor)? Or is it because of the small units of time being measured?
Thanks!
This was done 7 years ago! 🙂 I think the whole program is there, but you might like to try and break it down to get different parts working.
If this is not the full program then can I have the full program please?
I tried but it only taps once! Help?