Shooting Range Made From Lego Mindstorm NXT
by the_anykey in Outside > Launchers
6381 Views, 24 Favorites, 0 Comments
Shooting Range Made From Lego Mindstorm NXT
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);
}
}