Saturday, 18 August 2012

How to create/upload 'Hello World' leJOS NXJ

Assuming you have followed the leJOS installation and configuration instructions on this site...

Create

  1. Start Eclipse.
  2. From the File menu select New and then LeJOS NXT Project.
  3. Eclipse will popup the New LeJOS NXT Project dialog. Enter HelloWorld in the Project name textbox and click on the Finish button.
  4. The New LeJOS NXT Project dialog will close.
  5. From the File menu select New and then Class.
  6. Eclipse will popup the New Java Class dialog. Enter HelloWorld in the Name textbox, enter examples in the Package textbox, check the public static void main and click on the Finish button.
  7. Eclipse will generate an empty class with a main method. Add the import lejos.nxt.*; and the usual System.out.println("Hello World"); statement. Finally enter the following statement Button.waitForAnyPress();. See the example below.
  8.  
Note without the Button.waitForAnyPress() statement the Hello World message would be missed on the NXT.

Upload

Assuming there are no errors...
  1. Ensure the NXT is plugged in to the USB port and power on.
  2. From the File menu select Run, then Run As and then LeJOS NXT Program.
  3. Sometime later you should here the NXT beep and display 'Hello World'.

References

Intelligence Unleashed. Brian Bagnall. ISBN 978-0-9868322-0-8

No comments:

Post a Comment