Introduction: Shooting Range Made From Lego Mindstorm NXT

About: Hi, I am Richard, Father of 1 son + 2 step sons, so we have a house full of Lego. I have had lego for decades, including Lego mindstorms. I like to make things. In my little garage I have a large CNC machine,…
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);

   }
}

Toy Challenge 2

Participated in the
Toy Challenge 2