Guest User

Programm Nr1

a guest
Mar 25th, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.07 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2012 Project-Storm <http://projectstorm-bki.blogspot.com/>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18.  
  19. import lejos.nxt.Button;
  20. import lejos.nxt.Motor;
  21. import lejos.nxt.UltrasonicSensor;
  22. import lejos.nxt.I2CSensor;
  23. import lejos.nxt.SensorPort;
  24. import lejos.robotics.*;
  25. import lejos.nxt.TouchSensor;
  26. import lejos.nxt.*;
  27.  
  28. public class nxtProgramm1
  29. {
  30.   public static void main(String[] args) throws InterruptedException
  31.   {
  32.     System.out.println("NXT starts programme...");
  33.     UltrasonicSensor sonic = new UltrasonicSensor(SensorPort.S4);  //Distanzsensor Initialisierung
  34.     TouchSensor touch = new TouchSensor(SensorPort.S1);            //TouchSensor Initialisierung
  35.    
  36.     Motor.B.setSpeed(700);
  37.     Motor.C.setSpeed(700);
  38.     Motor.B.forward();
  39.     Motor.C.forward();
  40.    
  41.     while (true)
  42.     {
  43.        if(sonic.getRange() < 80.0f)   //Wenn das Objekt 80cm entfernt ist dann...
  44.        {
  45.            for(int itr = 700; itr >=0; itr--)  //Sanft abbremsen
  46.            {
  47.               Motor.B.setSpeed(itr);
  48.               Motor.C.setSpeed(itr);
  49.               Thread.sleep(5);
  50.            }
  51.            System.out.println("Objekt erkannt!!");  //Ausgabe
  52.            break;  //Schleife beenden
  53.  
  54.        }
  55.        
  56.        if (touch.isPressed())   //Wenn der TouchSensor gedrückt ist, dann
  57.           break;                //Schleife abbrechen
  58.     }
  59.  
  60.     Button.waitForAnyPress();
  61.   }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment