Presentation is loading. Please wait.

Presentation is loading. Please wait.

IT Basic Wednesday 14 April 2010

Similar presentations


Presentation on theme: "IT Basic Wednesday 14 April 2010"— Presentation transcript:

1 IT Basic Wednesday 14 April 2010
27. august 2018 IT Basic Wednesday 14 April 2010 Technical Faculty - Campus Horsens, Henrik Kronborg Pedersen – Hanne Bundgaard

2 Agenda LeJOS and java elements Picking up blue or red balls
Technical Faculty - Campus Horsens, Henrik Kronborg Pedersen –

3 Don’t forget the steps….
Eclipse New Java Project New Class Write the class Save Command Prompt Go to project folder (workspace\project\src) Compile the class (nxjc) Link and upload (nxj) Technical Faculty - Campus Horsens, Henrik Kronborg Pedersen –

4 The java class import lejos.nxt.*; public class HelloWorld {
Class file must be named the same ( HelloWorld.java) import lejos.nxt.*; public class HelloWorld { public static void main (String[] aArg) throws Exception LCD.drawString("Hello World",3,4); Thread.sleep(2000); } Technical Faculty - Campus Horsens, Henrik Kronborg Pedersen –

5 The java class import lejos.nxt.*; public class HelloWorld {
To use LeJOS we must import the tools This is where motors and sensors are defined import lejos.nxt.*; public class HelloWorld { public static void main (String[] aArg) throws Exception LCD.drawString("Hello World",3,4); Thread.sleep(2000); } Technical Faculty - Campus Horsens, Henrik Kronborg Pedersen –

6 The java class import lejos.nxt.*; public class HelloWorld {
public static void main (String[] aArg) throws Exception LCD.drawString("Hello World",3,4); Thread.sleep(2000); } The main method must exist and is the starting method of your system Just write it this way Technical Faculty - Campus Horsens, Henrik Kronborg Pedersen –

7 The java class import lejos.nxt.*; public class HelloWorld {
Sometimes exception handling is required – then add the throws exception to your method import lejos.nxt.*; public class HelloWorld { public static void main (String[] aArg) throws Exception LCD.drawString("Hello World",3,4); Thread.sleep(2000); } Technical Faculty - Campus Horsens, Henrik Kronborg Pedersen –

8 The java class import lejos.nxt.*; public class HelloWorld {
public static void main (String[] aArg) throws Exception LCD.drawString("Hello World",3,4); Thread.sleep(2000); } In methods we execute statements Technical Faculty - Campus Horsens, Henrik Kronborg Pedersen –

9 For loop import lejos.nxt.*; public class TenCount { public static void main (String[] aArg) throws Exception for(int count=1; count<11; count++) LCD.drawString("Count is: " + i, 3, 4); Thread.sleep(1000); } Technical Faculty - Campus Horsens, Henrik Kronborg Pedersen –

10 while loop int count = 1; while (count < 11) { LCD.drawString("Count is: " + count, 3, 4); count++; Thread.sleep(1000); } Google: java while Count++ Is the same as Count = count+1 Technical Faculty - Campus Horsens, Henrik Kronborg Pedersen –

11 If statement if (bump.isPressed()) { right(); } else left(); Google: java if Technical Faculty - Campus Horsens, Henrik Kronborg Pedersen –

12 FollowLine so far import lejos.nxt.*; public class FollowLine { public static void main(String[] args) throws Exception LightSensor light = new LightSensor(SensorPort.S1); while (true) forward(); if (light.readValue() < 40) left(); } if (light.readValue() >= 40) right(); private static void forward() { Motor.A.forward(); Motor.C.forward(); } private static void left() throws Exception Motor.A.stop(); Thread.sleep(500); forward(); private static void right() throws Exception Motor.C.stop(); } //end class Technical Faculty - Campus Horsens, Henrik Kronborg Pedersen –

13 Exercise 1 Count to 10 If a button is pressed before 10, count backwards Technical Faculty - Campus Horsens, Henrik Kronborg Pedersen –

14 Exercise 2 Let your robot follow the line If it meets a red ball
Write: ”Found red ball” in the display Pick it up Turn to the right Drop the ball If a button is pressed, pick up blue balls instead Technical Faculty - Campus Horsens, Henrik Kronborg Pedersen –


Download ppt "IT Basic Wednesday 14 April 2010"

Similar presentations


Ads by Google