本文整理汇总了Java中lejos.nxt.Button类的典型用法代码示例。如果您正苦于以下问题:Java Button类的具体用法?Java Button怎么用?Java Button使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Button类属于lejos.nxt包,在下文中一共展示了Button类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: run
import lejos.nxt.Button; //导入依赖的package包/类
@Override
public void run() {
CS.resetCartesianZero();
LCD.clear();
Motor.A.forward();
Motor.B.backward();
LCD.drawString("a",1,5);
while(!Button.ESCAPE.isPressed()){
LCD.drawString("b",2,5);
int robotangle = (int) (Math.toDegrees(getRobotangle()));
LCD.clear();
LCD.drawInt(robotangle, 1, 1);
LCD.drawInt((int) getRobotpos().x, 1, 2);
LCD.drawInt((int) getRobotpos().y, 1, 3);
}
}
开发者ID:PeterOrneholm,项目名称:penemunxt,代码行数:20,代码来源:Navigation.java
示例2: run
import lejos.nxt.Button; //导入依赖的package包/类
@Override
public void run(){
CompassSensor C = new CompassSensor(SensorPort.S4);
while(!Button.ESCAPE.isPressed()){
LCD.clear();
if (DE!=null && DE.CN !=null){
//DE.CN.updatePosition();
LCD.drawString("A: " + String.valueOf(DE.CN.getAngle()), 1, 1);
LCD.drawString("X: " + String.valueOf(DE.CN.getX()), 1, 2);
LCD.drawString("Y: " + String.valueOf(DE.CN.getY()), 1, 3);
LCD.drawString("C: " + String.valueOf(C.getDegrees()), 1, 4);
}
LCD.refresh();
try {
Thread.sleep(100);
} catch (InterruptedException e) {;
}
}
}
开发者ID:PeterOrneholm,项目名称:penemunxt,代码行数:20,代码来源:NavigatorTest.java
示例3: main
import lejos.nxt.Button; //导入依赖的package包/类
public static void main (String[] args){
FactoryTruck pilot = PilotFactory.getDefaultPilot();
pilot.setRotateSpeed(50.0);
UltrasonicSensor ultrasonicSensor = new UltrasonicSensor(ULTRASONIC_SENSOR_PORT);
LightSensor lightSensor = new LightSensor(LIGHT_SENSOR_PORT);
System.out.println("Press a Button" + "\nto start...");
Button.waitForAnyPress();
Sound.beep();
Behavior[] behaviors = {
new NormalBehavior(ultrasonicSensor),
new DriveForwardBehavior(pilot, ultrasonicSensor, lightSensor),
new RightCurveBehavior(pilot, ultrasonicSensor)
};
Arbitrator arbitrator = new Arbitrator(behaviors, true);
arbitrator.start();
}
开发者ID:MagicMayer,项目名称:as14_factory,代码行数:18,代码来源:FactoryTruckNXT.java
示例4: start
import lejos.nxt.Button; //导入依赖的package包/类
public void start () {
ExtendedMovement move = new ExtendedMovement(this.pos);
WallDetector wd = new WallDetector(this.pos);
wd.changeHeadPosition(); // Met vers l'avant
Thread wdThread = new Thread(wd);
wdThread.start();/**/
wd.addObserver(move);
this.ldThread.start();
LineObserver lo = new LineObserver(move, this.pos);
this.ld.addObserver(lo);
Exploitation exploit = new Exploitation(this.pos, this.grid, move);
exploit.solve();/**/
this.ld.stop();
wd.stop();
System.out.println("Before join");
try {
this.ldThread.join();
System.out.println("After join 1");
wdThread.join();
System.out.println("After join 2");
} catch (InterruptedException e1) {
e1.printStackTrace();
}
if (wd.isInFrontPosition())
wd.changeHeadPosition();/**/
Button.waitForAnyPress();
}
开发者ID:yoann-dufresne,项目名称:AFIA_Robots,代码行数:35,代码来源:MainExploitation.java
示例5: run
import lejos.nxt.Button; //导入依赖的package包/类
@Override
public void run() {
int Tolerance = 5;
int HeadFor;
CompassSensor sensor = new CompassSensor(SensorPort.S1);
Motor.A.setSpeed(5);
sensor.resetCartesianZero();
HeadFor = (int) sensor.getDegreesCartesian();
while(!Button.ESCAPE.isPressed()) {
LCD.drawInt((int) HeadFor, 1, 1);
LCD.drawInt((int) Motor.A.getTachoCount(), 1, 2);
LCD.drawInt((int) sensor.getDegreesCartesian(), 1, 3);
if(sensor.getDegreesCartesian() > (HeadFor + Tolerance)){
LCD.drawInt(1, 1, 4);
Motor.A.backward();
}else if(sensor.getDegreesCartesian() < (HeadFor - Tolerance)){
LCD.drawInt(2, 1, 4);
Motor.A.forward();
}else{
Motor.A.stop();
LCD.drawInt(0, 1, 4);
}
LCD.refresh();
try {
Thread.sleep(25);
} catch (InterruptedException e) {
}
LCD.clear();
}
}
开发者ID:PeterOrneholm,项目名称:penemunxt,代码行数:38,代码来源:CompassTest.java
示例6: main
import lejos.nxt.Button; //导入依赖的package包/类
public static void main(String args[]) throws InterruptedException{
TiltSensor TS = new TiltSensor(SensorPort.S3);
while (!Button.ESCAPE.isPressed()){
LCD.drawInt(TS.getXAccel(), 2, 1);
LCD.drawInt(TS.getYAccel(), 2, 2);
LCD.drawInt(TS.getZAccel(), 2, 3);
LCD.drawInt(TS.getXTilt(), 2, 4);
LCD.drawInt(TS.getYTilt(), 2, 5);
LCD.drawInt(TS.getZTilt(), 2, 6);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
}
}
开发者ID:PeterOrneholm,项目名称:penemunxt,代码行数:16,代码来源:TiltTest.java
示例7: main
import lejos.nxt.Button; //导入依赖的package包/类
public static void main(String args[]) throws InterruptedException{
LCD.drawString("Hello World!", 1, 1);
LCD.drawString("Second line", 1, 2);
LCD.drawString("Third line", 1, 3);
Button.ESCAPE.waitForPressAndRelease();
}
开发者ID:PeterOrneholm,项目名称:penemunxt,代码行数:9,代码来源:HelloWorld.java
示例8: main
import lejos.nxt.Button; //导入依赖的package包/类
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Press any button to start");
Button.waitForAnyPress();
init();
moveForward();
// Solange der Abbruch-Knopf nicht gedr�ckt wurde
while (!EXIT.isPressed()) {
// Falls sich der Zustand ge�ndert hat
if (changedState()) {
// Falls der Roboter auf der Linie ist
if (isOnLine()) {
// SearchThread falls er existiert stoppen
if (searchThread != null) {
searchThread.stopSearching();
}
// Vorw�rtsbewegung einleiten
moveForward();
} else {
// Falls der Roboter neben der Linie ist
// Vorw�rtsbewegung stoppen
stopMoving();
// Neuen Such-Thread anlegen und starten
searchThread = new SearchThread(L, R);
searchThread.start();
}
}
}
// Suche anhalten
searchThread.stopSearching();
}
开发者ID:xladde,项目名称:hsw,代码行数:32,代码来源:BigCourse.java
示例9: main
import lejos.nxt.Button; //导入依赖的package包/类
public static void main(String[] args) {
CompassSensor CS = new CompassSensor(SensorPort.S2);
while(!Button.ESCAPE.isPressed()){
Sound.playTone((int) CS.getDegrees()*10, 10, 75);
}
}
开发者ID:PeterOrneholm,项目名称:penemunxt,代码行数:7,代码来源:CompassTest.java
示例10: WriteMessageAndWait
import lejos.nxt.Button; //导入依赖的package包/类
public static void WriteMessageAndWait(String Message) {
LCD.clear();
LCD.drawString(Message, 1, 1);
LCD.refresh();
Button.ENTER.waitForPressAndRelease();
}
开发者ID:PeterOrneholm,项目名称:penemunxt,代码行数:7,代码来源:NXTDebug.java
示例11: checkUserInput
import lejos.nxt.Button; //导入依赖的package包/类
/**
*
* check the user input and set the status if necessary
*
* @throws Exception
*
*/
private static void checkUserInput() throws Exception{
while( true ){
//
// react on user inputs and change the status or change
// variables
if( Button.ENTER.isPressed() ){
if( status == SHOW_MAIN_SCREEN ) { status = START_PROGRAM; break; }
else if( status == SET_OUTER_DIR ) { status = SET_INNER_DIR; break; }
else if( status == SET_INNER_DIR ) { status = SET_MOTORSPEED; break; }
else if( status == SET_MOTORSPEED ) { status = SET_LIGHT; break; }
else if( status == SET_LIGHT ) { status = SET_OUTER_DIR ; break; }
}
else if( Button.ESCAPE.isPressed() ){
if( status == SHOW_MAIN_SCREEN ) { status = STOP_PROGRAM; break; }
else { status = SHOW_MAIN_SCREEN; break; }
}
else if( Button.RIGHT.isPressed() ){
if( status == SHOW_MAIN_SCREEN ){ status = SHOW_INFO; break; }
else if( status == SET_OUTER_DIR && outerdir < 180 ){ outerdir += 5 ; break; }
else if( status == SET_INNER_DIR && innerdir < 90 ){ innerdir += 5; break; }
else if( status == SET_MOTORSPEED && motorSpeed < 1000 ){ motorSpeed += 50; break; }
else if( status == SET_LIGHT && minLight < 500 ){ minLight += 5; break; }
}
else if( Button.LEFT.isPressed() ){
if( status == SHOW_MAIN_SCREEN ){ status = SET_OUTER_DIR; break; }
else if( status == SET_OUTER_DIR && outerdir > 5 ){ outerdir -= 5; break; }
else if( status == SET_INNER_DIR && innerdir > 10){ innerdir -= 5; break; }
else if( status == SET_MOTORSPEED && motorSpeed > 50){ motorSpeed -= 50; break; }
else if( status == SET_LIGHT && minLight > 250 ){ minLight -= 5; break; }
}
}
// Wait if no button is clicked ( bug of the NXT )
//
while( true ){
boolean clicked = false;
for( Button i : Button.BUTTONS ){
// if one button is clicked, change it to true
if( i.isPressed() ) clicked = true;
}
// if no button is pressed, break loop
if( !clicked ) break;
}
}
开发者ID:xladde,项目名称:hsw,代码行数:59,代码来源:Linie.java
示例12: loop
import lejos.nxt.Button; //导入依赖的package包/类
/**
*
* The complete robot life cycle
*
* @throws Exception
*
*/
private static void loop() throws Exception{
initRobot();
while( ! Button.ESCAPE.isPressed() ){
// Print out status information on LCD
outputStatus();
// check status and do action
switch( status ){
// robot is on the black line
case ON_LINE :
// check position, if not on line, stop the engines
if( ! isOnLine() ){
stopEngines();
status = NOT_ON_LINE;
}
break;
// robot is not longer on the
// black line
case NOT_ON_LINE :
// rotate to line and if successful, start engines again
if( rotateToLine() ) initRobot();
// if rotating to line fails, stop program with an error
else status = ERROR;
break;
// error status
case ERROR :
// draw message
LCD.clear();
LCD.drawString( "!! ERROR !!", 1, 3);
// wait for input
while( ! Button.ESCAPE.isPressed() ){
Thread.sleep(10);
}
// exit
System.exit(0);
break;
}
}
}
开发者ID:xladde,项目名称:hsw,代码行数:60,代码来源:Linie.java
示例13: addExitListener
import lejos.nxt.Button; //导入依赖的package包/类
/**
* Einrichten eines Abbruch-Buttons. Ein Beenden des Programms erfolgt
* nachdem der {@link Button#ESCAPE Escape-Button} eine Sekunde gedrückt
* gehalten wurde.
*/
public static void addExitListener() {
addExitListener(Button.ESCAPE, 1000);
}
开发者ID:jneug,项目名称:upb.LeJOS,代码行数:9,代码来源:ButtonUtils.java
注:本文中的lejos.nxt.Button类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论