当前位置: 首页>>代码示例>>Java>>正文


Java Button类代码示例

本文整理汇总了Java中lejos.hardware.Button的典型用法代码示例。如果您正苦于以下问题:Java Button类的具体用法?Java Button怎么用?Java Button使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Button类属于lejos.hardware包,在下文中一共展示了Button类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import lejos.hardware.Button; //导入依赖的package包/类
public static void main(String[] args) {
	EV3 ev3 = (EV3) BrickFinder.getLocal();
	TextLCD lcd = ev3.getTextLCD();
	Keys keys = ev3.getKeys();

	// File root = new File(".");
	// String[] files = root.list();
	// for(int i = 0; i < files.length; i++)
	// lcd.drawString(files[i], 0, i);

	Audio audio = ev3.getAudio();
	audio.playSample(new File("hackathon.wav"), 100);

	LCD.drawString("Enter to Exit", 0, 2);
	Button.ENTER.waitForPressAndRelease();

	// audio.playNote(Audio.XYLOPHONE, 420, 500);
	// audio.playNote(Audio.XYLOPHONE, 510, 500);
	// audio.playNote(Audio.XYLOPHONE, 420, 500);
	// audio.playNote(Audio.XYLOPHONE, 640, 500);
	// audio.playNote(Audio.XYLOPHONE, 220, 500);
	// keys.waitForAnyPress();

}
 
开发者ID:iproduct,项目名称:course-social-robotics,代码行数:25,代码来源:AudioDemo02.java

示例2: adjustAngle

import lejos.hardware.Button; //导入依赖的package包/类
private void adjustAngle(boolean reverse) {
    pilot.travel(-MOVE_DISTANCE_TO_ADJUST_ANGLE);
    double firstDist = getAccurateDistance(); // 15.48
    pilot.travel(MOVE_DISTANCE_TO_ADJUST_ANGLE);
    double secondDist = getAccurateDistance(); // 9.5
    double tantheta = (secondDist - firstDist) / MOVE_DISTANCE_TO_ADJUST_ANGLE;
    if (Math.abs(secondDist - firstDist) > 10 || firstDist > OCCUPIED_THRESHOLD || secondDist > OCCUPIED_THRESHOLD) {
        return;
    }
    double theta = Math.atan(tantheta) * 180 / Math.PI;
    System.out.println("theta: " + theta);
    if (Math.abs(theta) > ADJUST_ANGLE_THRESHOLD) {
        Button.waitForAnyEvent();
        theta = 0;
    }
    theta *= reverse ? -1 : 1;
    pilot.rotate(theta);
}
 
开发者ID:JINKEHE,项目名称:Rescue-Victims,代码行数:19,代码来源:Megatron.java

示例3: main

import lejos.hardware.Button; //导入依赖的package包/类
public static void main(String[] args) {

        LCD.drawString("Starting EventBot", 2, 3);

        EventGrab grabbie = new EventGrab();
        grabbie.init();

        //grabbie.touchSensor.addListener(event -> LCD.drawString("Touched!" + System.currentTimeMillis(), 2, 3));
        Button.waitForAnyPress();
        grabbie.infraredSensor.readData();
        Button.waitForAnyPress();
        grabbie.infraredSensor.readData();
        Button.waitForAnyPress();
        grabbie.infraredSensor.readData();
        Button.waitForAnyPress();
        grabbie.infraredSensor.readData();


        LCD.drawString("Kill EventBot - click to continue", 2, 3);
        Button.waitForAnyPress();
        //grabbie.touchSensor.stopSensor();

    }
 
开发者ID:jweijers,项目名称:EV3-robots,代码行数:24,代码来源:EventGrab.java

示例4: main

import lejos.hardware.Button; //导入依赖的package包/类
public static void main(String[] args) {
  helper = new EV3Helper();

  System.out.println("IteraBot reporting for duty\nClick any button to start robot");

  Button.waitForAnyPress();

  /*
   * Drives forward 30cm, rotates left 90 degrees, drives forward 30cm.
   * Stops if the distance sensor registers an object closer than 20cm. 
   */
  while(stopIfDistanceLessThan(20)){
    helper.forward(30);
    if(stopIfDistanceLessThan(20)){
      break;
    }
    helper.turnLeft(90);
  }
}
 
开发者ID:magnusbae,项目名称:HelloBrick,代码行数:20,代码来源:Main.java

示例5: main

import lejos.hardware.Button; //导入依赖的package包/类
/**
 * @param args
 */
public static void main(String[] args) {
	 GraphicsLCD g = BrickFinder.getDefault().getGraphicsLCD();
	 final int SW = g.getWidth();
	 final int SH = g.getHeight();
	 Button.LEDPattern(4);
	 Sound.beepSequenceUp();
	 g.setFont(Font.getDefaultFont());
	 g.drawString("Lejos EV3 Gradle", SW/2, SH/2, GraphicsLCD.BASELINE|GraphicsLCD.HCENTER);
	 Button.LEDPattern(3);
	 Delay.msDelay(4000);
	 Button.LEDPattern(5);
	 g.clear();
	 g.refresh();
	 Sound.beepSequence();
	 Delay.msDelay(500);
	 Button.LEDPattern(0); 
}
 
开发者ID:jornfranke,项目名称:lejos-ev3-example,代码行数:21,代码来源:RobotApplication.java

示例6: followWall

import lejos.hardware.Button; //导入依赖的package包/类
void followWall() {
    logger.trace("followWall");
    MovePopulation population = new MovePopulation(rand);

    Move move;
    SensorReading prevReading;
    SensorReading curReading = readSensors();

    boolean done = false;
    while (!done) {
        move = population.getMoveForReading(curReading);
        execute(move);

        prevReading = curReading;
        curReading = readSensors();

        move.fitness.scoreMove(prevReading, curReading);

        if (Button.readButtons() != 0) {
            done = true;
        }
    }
}
 
开发者ID:RadicalZephyr,项目名称:ev3java,代码行数:24,代码来源:Main.java

示例7: main

import lejos.hardware.Button; //导入依赖的package包/类
public static void main(String[] args) {
	log.info("Initializing...");
	LCD.clear();
	disableOtherLogLayers();
	LCD.clear();
	Button.setKeyClickVolume(1);
	SystemTime.initSysTime();
	ClockProperties clockProperties = ClockProperties.getInstance();
	AnalogClock clock = new AnalogClock(clockProperties, new TickPeriod(5,
			TimeUnit.SECONDS), new Time(0, 20),
			MirrorMotor
					.invertMotor(new EV3MediumRegulatedMotor(MotorPort.A)),
			MirrorMotor
					.invertMotor(new EV3LargeRegulatedMotor(MotorPort.B)));
	MainWithMenu mainWithMenu = new MainWithMenu(clock);
	log.info("Ready");
	Sound.beep();
	mainWithMenu.start();
}
 
开发者ID:rafalmag,项目名称:EV3-projects,代码行数:20,代码来源:MainWithMenu.java

示例8: run

import lejos.hardware.Button; //导入依赖的package包/类
@Override
public void run() {
	if (Button.waitForAnyEvent() == Button.ID_ESCAPE) {
		try {
			this.connection.close();
		} catch (IOException e) {
			System.err.println("Error when closing connection: " + e.getMessage());
		}
		if (this.debugPrint)
			System.out.println("Closing connection...");
	}
}
 
开发者ID:alisharif2,项目名称:dpm-project,代码行数:13,代码来源:WifiConnection.java

示例9: run

import lejos.hardware.Button; //导入依赖的package包/类
public void run() {
    while (true) {
        if (Button.getButtons() == Keys.ID_ESCAPE) {
            try {
                robot.stop();
            } catch (IOException e) {
                // this won't happen
            }
        }
    }
}
 
开发者ID:JINKEHE,项目名称:Rescue-Victims,代码行数:12,代码来源:StoppingThread.java

示例10: main

import lejos.hardware.Button; //导入依赖的package包/类
public static void main(String[] args) {
    LCD.drawString("Hello world", 2, 3);
    Button.waitForAnyPress();
    EV3MediumRegulatedMotor ev3MediumRegulatedMotor = new EV3MediumRegulatedMotor(MotorPort.C);
    resetSmallEngine(ev3MediumRegulatedMotor);
    grab(ev3MediumRegulatedMotor);
    LCD.drawString("Position: " + ev3MediumRegulatedMotor.getPosition(), 2, 3);
    resetSmallEngine(ev3MediumRegulatedMotor);

    Button.waitForAnyPress();
}
 
开发者ID:jweijers,项目名称:EV3-robots,代码行数:12,代码来源:Hello.java

示例11: getButtonPress

import lejos.hardware.Button; //导入依赖的package包/类
/**
 * Read a button press.
 * If the read timesout then exit the system.
 *
 * @return The bitcode of the button.
 */
private int getButtonPress() {
    int value = Button.waitForAnyPress(this.timeout * 60000);
    if ( value == 0 ) {
        shutdown();
    }
    return value;
}
 
开发者ID:OpenRoberta,项目名称:robertalab-ev3lejos-v0,代码行数:14,代码来源:GraphicStartup.java

示例12: stopProgram

import lejos.hardware.Button; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public void stopProgram() {
    try {
        if ( program == null ) {
            return;
        }

        program.destroy();

        System.out.println("Waiting for process to die");
        ;
        program.waitFor();
        System.out.println("Program finished");
        resetMotors();
        // Turn the LED off, in case left on
        Button.LEDPattern(0);
        lcd.setAutoRefresh(true);
        lcd.clear();
        lcd.refresh();
        program = null;
        suspend = false;
        this.ind.resume();
    } catch ( Exception e ) {
        System.err.println("Failed to stop program: " + e);
    }
}
 
开发者ID:OpenRoberta,项目名称:robertalab-ev3lejos-v0,代码行数:28,代码来源:GraphicStartup.java

示例13: getSelection

import lejos.hardware.Button; //导入依赖的package包/类
/**
 * Obtain a menu item selection
 * Allow the user to make a selection from the specified menu item. If a
 * power off timeout has been specified and no choice is made within this
 * time power off the NXT.
 *
 * @param menu Menu to display.
 * @param cur Initial item to select.
 * @return Selected item or < 0 for escape etc.
 */
@SuppressWarnings("deprecation")
private int getSelection(GraphicMenu menu, int cur) {
    int selection;

    curMenu = menu;

    // If the menu is interrupted by another thread, redisplay
    do {
        selection = menu.select(cur, this.timeout * 60000);

        while ( suspend ) {
            if ( program != null && !echoIn.isAlive() && !echoErr.isAlive() ) {
                stopProgram();
                this.ind.resume();
                break;
            }
            int b = Button.getButtons();
            if ( b == 6 ) {
                if ( program != null ) {
                    stopProgram();
                }
                this.ind.resume();
                break;
            }
            Delay.msDelay(200);
        }
    } while ( selection == -2 );

    if ( selection == -3 ) {
        shutdown();
    }

    return selection;
}
 
开发者ID:OpenRoberta,项目名称:robertalab-ev3lejos-v0,代码行数:45,代码来源:GraphicStartup.java

示例14: uncaughtException

import lejos.hardware.Button; //导入依赖的package包/类
@Override
public void uncaughtException(Thread th, Throwable t)  {
	Sound.buzz();
    TextLCD lcd = LocalEV3.get().getTextLCD(Font.getSmallFont());
    int offset = 0;
    while (true)
    {
   		lcd.clear();
   		lcd.drawString("Uncaught exception:", offset, 0);
   		lcd.drawString(t.getClass().getName(), offset, 2);
   		if (t.getMessage() != null) lcd.drawString(t.getMessage(), offset, 3);		
   		
   		if (t.getCause() != null) {
   			lcd.drawString("Caused by:", offset, 5);
   			lcd.drawString(t.getCause().toString(), offset, 6);
   		}
   		
   		StackTraceElement[] trace = t.getStackTrace();
   		for(int i=0;i<7 && i < trace.length ;i++) lcd.drawString(trace[i].toString(), offset, 8+i);
   		
   		lcd.refresh();
   		int id = Button.waitForAnyEvent();
   		if (id == Button.ID_ESCAPE) break;
   		if (id == Button.ID_LEFT) offset += 5;
   		if (id == Button.ID_RIGHT)offset -= 5;
   		if (offset > 0) offset = 0;
    }
    
    // Shutdown the EV3
   	try {
		Runtime.getRuntime().exec("init 0");
	} catch (IOException e) {
		// Ignore
	}
    System.exit(1);
}
 
开发者ID:OpenRoberta,项目名称:robertalab-ev3lejos-v0,代码行数:37,代码来源:ExceptionHandler.java

示例15: main

import lejos.hardware.Button; //导入依赖的package包/类
public static void main(String[] args) {
	EV3 ev3 = (EV3) BrickFinder.getLocal();
	TextLCD lcd = ev3.getTextLCD();
	Keys keys = ev3.getKeys();

	// lcd.drawString("Hello Trayan", 4, 2);
	// lcd.drawString("from leJOS", 4, 3);

	// Open clow
	RegulatedMotor mA = new EV3LargeRegulatedMotor(MotorPort.A);

	while (true) {
		mA.resetTachoCount();
		lcd.drawString("Up - Close", 4, 2);
		lcd.drawString("Down - Open", 4, 3);
		lcd.drawString("Escape - Exit", 4, 4);

		// Simple menu
		keys.waitForAnyPress(60000);
		int maRotation = 0;
		if (Button.DOWN.isDown()) {
			maRotation = -620;
		} else if (Button.UP.isDown()) {
			maRotation = 620;
		}
		if (Button.ESCAPE.isDown()) {
			System.exit(0);
		}

		mA.rotateTo(maRotation, false);
		int count = mA.getTachoCount();
		lcd.drawString("Tacho: " + count, 0, 2);
	}

}
 
开发者ID:iproduct,项目名称:course-social-robotics,代码行数:36,代码来源:MoveClaw.java


注:本文中的lejos.hardware.Button类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。