Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Copyright (C) 2012 Project-Storm <http://projectstorm-bki.blogspot.com/>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- import lejos.nxt.Button;
- import lejos.nxt.Motor;
- import lejos.nxt.UltrasonicSensor;
- import lejos.nxt.I2CSensor;
- import lejos.nxt.SensorPort;
- import lejos.robotics.*;
- import lejos.nxt.TouchSensor;
- import lejos.nxt.*;
- public class nxtProgramm1
- {
- public static void main(String[] args) throws InterruptedException
- {
- System.out.println("NXT starts programme...");
- UltrasonicSensor sonic = new UltrasonicSensor(SensorPort.S4); //Distanzsensor Initialisierung
- TouchSensor touch = new TouchSensor(SensorPort.S1); //TouchSensor Initialisierung
- Motor.B.setSpeed(700);
- Motor.C.setSpeed(700);
- Motor.B.forward();
- Motor.C.forward();
- while (true)
- {
- if(sonic.getRange() < 80.0f) //Wenn das Objekt 80cm entfernt ist dann...
- {
- for(int itr = 700; itr >=0; itr--) //Sanft abbremsen
- {
- Motor.B.setSpeed(itr);
- Motor.C.setSpeed(itr);
- Thread.sleep(5);
- }
- System.out.println("Objekt erkannt!!"); //Ausgabe
- break; //Schleife beenden
- }
- if (touch.isPressed()) //Wenn der TouchSensor gedrückt ist, dann
- break; //Schleife abbrechen
- }
- Button.waitForAnyPress();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment