Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- COLOUR SENSOR CODE:
- import lejos.nxt.*;
- import lejos.robotics.*;
- public class colourSensor {
- public Color getColour() {
- ColorSensor RGBsensor = new ColorSensor(SensorPort.S1); //PORT DEFAULTED TO S1, NEED TO FIND A WAY TO PASS AS A PARAMETER IF POSSIBLE
- Color DetectedColour = RGBsensor.getColor(); //MAY NEED TO CHANGE TO GET COLORID
- return DetectedColour; //Returns detected colour as data type Colour
- }
- }
- _________________________________________________________________________________________________________________________________
- import lejos.nxt.*;
- import lejos.robotics.*;
- public class test {
- public static void main(String[] args) {
- //mainRobot robot = new mainRobot();
- //Clear previous movement and move forward
- LCD.drawString("program 1", 0, 0);
- Button.waitForAnyPress();
- LCD.clear();
- Motor.A.forward();
- LCD.drawString("forward", 0, 0);
- //Move backwards
- Button.waitForAnyPress();
- LCD.drawString("backward", 0, 0);
- Motor.A.backward();
- //Stop the motor.
- Button.waitForAnyPress();
- Motor.A.stop();
- Color x = colourSensor.getColour();
- System.out.println();
- int counter = 0;
- level1Rob robot = new level1Rob();
- for(;;) {
- //If colour sensor does not find the coloured line display the message.
- if(robot.colourSensor(1) == false ) {
- System.out.println("no light found");
- Motor.A.forward(true);
- Motor.D.forward(true);
- }
- //If colour sensor does find the coloured line display the message.
- if(robot.ColourSensor(1) == true) {
- System.out.Println("Light source found");
- }
- //While the colour sensor has not found the coloured line, keep moving forward.
- while(robot.ColourSensor(1) == true ) {
- Motor.A.forward();
- }
- //Once the colour sensor has found the light, stop moving
- while(robot.ColourSensor(1) == false ) {
- Motor.A.stop();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement