Search
About

Damien works with students and teacher from around the world, bringing the effective use of technology to the classroom.  

LEGO MINDSTORMS
Damien is a member of the MCP (Mindstorms Community Program), a small group of experts who collaborate with LEGO to make the MINDSTORM product better.

VEX IQ Robotics
Damien is a member of the VEX IQ Super User group, a small group of experts who collaborate with VEX to make the VEX IQ platform a better product 

 

Books

Teacher Resource Books

Global Map

See where the DomaBot and RileyRover is being used around the world

« Card Dealing Robot | Main
Monday
Jun232008

Clap Back Robot

This robot samples any loud sounds and keeps track of the time between each. It then plays back the rhythm by tapping on a plastic container. The code is written in NXC and is a good example of how arrays can be used.

 

 

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 */

t0 = CurrentTick();/* Grab the current reading of the timer */

 

/* 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 */

time[i] = CurrentTick()-t0;

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 */

break;

}

/* 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);

}

 

EmailEmail Article to Friend

Reader Comments (6)

I tried but it only taps once! Help?

August 15, 2015 | Unregistered Commenterlego3708

If this is not the full program then can I have the full program please?

August 15, 2015 | Unregistered Commenterlego3708

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.

August 17, 2015 | Registered CommenterDamien Kee

Thanks!

August 23, 2015 | Unregistered Commenterlego3708

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?

February 24, 2016 | Unregistered CommenterJimmyC

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!

February 24, 2016 | Registered CommenterDamien Kee

PostPost a New Comment

Enter your information below to add a new comment.
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>