Hailfire Droid

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

Hailfire Droid

Postby mabusincarnate » Tue Feb 03, 2009 6:03 pm

I just finished my first "original" project so I thought I'd get some feedback. I took my inspiration from a guy on NXTLog, though I built this entirely on my own.

This is the first code I've written since high school computer science so it doesn't really do much. I'm using the tutorials on sun.com and learning as I go.

http://www.youtube.com/watch?v=iqBT-l7XtUU


Code: Select all
package org.me.mypackage;

import lejos.nxt.*;

public class HelloWorld {

   public static void main(String[] args) {
      UltrasonicSensor sonic = new UltrasonicSensor(SensorPort.S1);
      sonic.reset();
      sonic.getDistance();
      int distance = sonic.getDistance();
         while(!Button.ESCAPE.isPressed()){
            if(distance >= 25) {   
               distance = sonic.getDistance();
               Motor.A.setSpeed(900);
               Motor.B.setSpeed(900);               
               Motor.A.backward();
               Motor.B.backward();               
             }
            else {
               backUp();
               distance = sonic.getDistance();
            }
            
         }
   }
   
   public static void backUp(){
      
      Motor.A.stop();
      Motor.B.stop();            
      Motor.B.rotate(1000);
      Motor.B.stop();   
   }
}

mabusincarnate
New User
 
Posts: 15
Joined: Sun Jan 25, 2009 1:36 am
Location: Houston

Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 1 guest

cron
more stuff