3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

Shooting Range made from Lego Mindstorm NXT

Shooting Range made from Lego Mindstorm NXT
As we enjoy shooting out Nerf Blasters, I thought I would make a shooting range from Lego. The motors of Lego Mindstorm NXT have build in rotation detection, so they can be used and output an input. First the program at random picks one of the 3 motors and placed the target up. Then using the rotation detection it will detect a 'hit'. This happens with the slightest movement (1 degree or more). When the hit is detected the motor turn the target all the way down and a new random target is selected.

http://www.youtube.com/watch?v=E1wt5ywUo9M
 
The Lego code (designed in Bricx Command Center):

#define Power 75
#define DownTime 200
#define UpTime 200
#define TimePerTarget 2000

task main()
{

long rotate; /* the variable for recording angle */
long nothit;
int welke;
int m;
int score;
long time,time2;

TextOut(0,LCD_LINE2,"Angle on PortA");
score =0;
  TextOut(0,LCD_LINE7,"Score:");
NumOut(40,LCD_LINE7,score);


while (true) {

OnFwd(OUT_ABC,Power);
Wait(DownTime);
Off(OUT_ABC);

Wait(2000);

welke = Random(3);
NumOut(0,LCD_LINE4,welke);

if (welke ==0) { m=OUT_A; }
if (welke ==1) { m=OUT_B; }
if (welke ==2) { m=OUT_C; }

OnRev(m,Power);
Wait(UpTime);
Off(m);

Wait(400);
nothit = MotorRotationCount (m);
rotate = nothit;
NumOut(0,LCD_LINE6,nothit);

time = CurrentTick();

while (nothit == rotate) {
rotate=MotorRotationCount (m); /* Read Motor angle [deg]*/
TextOut(0,LCD_LINE5," ");
NumOut(0,LCD_LINE5,rotate);
TextOut(40,LCD_LINE5,"deg");


//if ((time+TimePerTarget) < CurrentTick())
// { rotate = rotate + 10; }

}

OnFwd(m,Power);
Wait(DownTime);
Off(m);

score = score +1;

TextOut(0,LCD_LINE7,"Score:");
NumOut(40,LCD_LINE7,score);

   }
}

1 comment

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
0
Followers
1
Author:the_anykey