本文整理汇总了Java中lejos.hardware.Sound类的典型用法代码示例。如果您正苦于以下问题:Java Sound类的具体用法?Java Sound怎么用?Java Sound使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Sound类属于lejos.hardware包,在下文中一共展示了Sound类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import lejos.hardware.Sound; //导入依赖的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);
}
示例2: main
import lejos.hardware.Sound; //导入依赖的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();
}
示例3: doLocalization
import lejos.hardware.Sound; //导入依赖的package包/类
public void doLocalization() {
// drive to location listed in tutorial
// start rotating and clock all 4 gridlines
// do trig to compute (0,0) and 0 degrees
// when done travel to (0,0) and turn to 0 degrees
Navigation localizerLocomotor = new Navigation(this.odo);
/* Store the angles that each axis is crossed at in an array
* [0] -> y-
* [1] -> x+
* [2] -> y+
* [3] -> x-
*/
ArrayList<Double> angles = new ArrayList<Double>();
// Start the robot rotating
localizerLocomotor.setSpeeds(-ROTATION_SPEED, ROTATION_SPEED);
// This code assumes wer're in the third quadrant
while(angles.size() < 4) {
if(colorSensor.getFilteredData() < BLACK_RGB) {
Sound.beep();
angles.add(odo.getAng());
Delay.msDelay(AXIS_CROSS_DELAY);
}
}
localizerLocomotor.halt();
// Now let's do some math
// Lets calculate our x position
double x = (-COLOR_SENSOR_OFFSET) * Math.cos(Math.toRadians(Math.abs(angles.get(0) - angles.get(2)))/2);
// Lets calculate our y position
double y = (COLOR_SENSOR_OFFSET) * Math.cos(Math.toRadians(Math.abs(angles.get(1) - angles.get(3)))/2);
// Let's calculate our heading correction
double headingCorrection = odo.getAng() + 270 - angles.get(0) + (Math.abs(angles.get(0) - angles.get(2)))/2;
odo.setPosition(new double [] {x, y, headingCorrection}, new boolean [] {true, true, true});
}
示例4: fire
import lejos.hardware.Sound; //导入依赖的package包/类
@Override
public void fire() {
GlobalDefinitions.SHOOTMOTOR.rotate(-250);
Sound.beep();
GlobalDefinitions.SHOOTMOTOR.rotate(250);
}
示例5: dropBall
import lejos.hardware.Sound; //导入依赖的package包/类
public void dropBall(){
GlobalDefinitions.SHOOTMOTOR.setSpeed(300);
GlobalDefinitions.SHOOTMOTOR.rotate(500);
Sound.beep();
GlobalDefinitions.SHOOTMOTOR.setSpeed(50);
GlobalDefinitions.SHOOTMOTOR.rotate(-500);
GlobalDefinitions.SHOOTMOTOR.setSpeed(300);
}
示例6: stop
import lejos.hardware.Sound; //导入依赖的package包/类
public void stop() throws IOException {
pilot.stop();
Sound.beepSequenceUp();
sock.close();
server.close();
System.exit(0);
}
示例7: Megatron
import lejos.hardware.Sound; //导入依赖的package包/类
public Megatron() {
ev3 = BrickFinder.getDefault();
setupPilot();
setupColorSensor();
getColorName();
setupUltrasonicSensor();
setupServer();
stoppingThread = new StoppingThread(this);
stoppingThread.start();
while (true) {
try {
String command = input.readLine();
System.out.println("Command: " + command);
if (command.equals("get(color)")) {
pilot.travel(-MOVE_BACK_DISTANCE);
String theColor = getColorName();
pilot.travel(MOVE_BACK_DISTANCE);
if (theColor.equals(BLUE) || theColor.equals(RED) || theColor.equals(GREEN))
Sound.beep();
output.println(theColor);
} else if (command.equals("get(occupied)")) {
output.println(getOccupiedInfo());
} else if (command.startsWith("move")) {
String[] parameters = getParameters(command);
output.println(moveRelatively(parameters[0],parameters[1]));
firstStepFinished = true;
} else if (command.equals("end")) {
doCelebration();
output.println(DONE);
}
output.flush();
} catch (IOException e) {
}
}
}
示例8: uncaughtException
import lejos.hardware.Sound; //导入依赖的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);
}
示例9: playTune
import lejos.hardware.Sound; //导入依赖的package包/类
/**
* Play the leJOS startup tune.
*/
static void playTune()
{
if (Sound.playSample(new File("lejos.wav")) == 0)
return;
int[] freq = { 523, 784, 659 };
for (int i = 0; i < 3; i++) {
Sound.playTone(freq[i], 300);
//Sound.pause(300);
}
}
示例10: detect_obstacle
import lejos.hardware.Sound; //导入依赖的package包/类
private void detect_obstacle()
{
if (sensor.distance() < 30) // If we are close to an obstacle inhibit DriveForward.output thereby stopping the robot
{
log("Obstacle Detected");
mOutput.inhibit();
log("Inhibiting Output");
if (++mCount >= MAXCOUNT) // If the number of obstacles detected to date exceeds MAXCOUNT we stop execution
{
log(String.format("Obstacle # %d. Stopping robot.", mCount));
Sound.twoBeeps(); // Beep twice to signal the end of the program
hold(200); // Wait for 200 ms and then shutdown the program
BumperCar.exit(); // Initiate graceful exit strategy
hold(200); // Wait for 200 ms to allow the exit to proceed
}
else // Carry out the behavior required by this module when an obstacle is detected
{
hold(100); // We stop the forward motion, reverse a bit to create space and then turn left
short_reverse();
turn_left();
mOutput.allow(); // Removes inhibition on the Output allowing that module to access it
log("Removing inhibition on Output");
}
}
}
示例11: promptForStartPush
import lejos.hardware.Sound; //导入依赖的package包/类
void promptForStartPush() {
logger.trace("promptForStartPush");
Sound.twoBeeps();
Sound.beep();
LCD.clear();
LCD.drawString("Please push any", 1, 1);
LCD.drawString("button to begin.", 1, 3);
Button.waitForAnyPress();
LCD.clear();
LCD.drawString("Running...", 1, 1);
}
示例12: should_play_file
import lejos.hardware.Sound; //导入依赖的package包/类
@Test
public void should_play_file() throws Exception {
// given
try (InputStream is = getClass().getResourceAsStream(
"/" + Cuckoo.CUCKOO_WAV)) {
if (is == null) {
throw new IOException("Cannot find wav=" + Cuckoo.CUCKOO_WAV);
}
SoundMock soundMock = new SoundMock(new NativeDeviceMock());
// when
int errorCode = soundMock.playSample(is, Sound.VOL_MAX);
// then
assertThat(errorCode, equalTo(0));
}
}
示例13: main
import lejos.hardware.Sound; //导入依赖的package包/类
public static void main(String[] args) {
LCD.clear();
LCD.drawString("First EV3 Program", 0, 5);
Sound.beep();
Button.waitForAnyPress();
LCD.clear();
LCD.refresh();
}
示例14: startBeeps
import lejos.hardware.Sound; //导入依赖的package包/类
/**
* Warn user the Ballbot is about to start balancing.
*/
private static void startBeeps() {
LCD.clear();
LCD.drawString("leJOS NXJ Ballbot", 0, 1);
LCD.drawString("Balance in", 0, 3);
// Play warning beep sequence to indicate balance about to start
for (int c=8; c>=0;c--) {
LCD.drawInt(c, 5, 4);
Sound.playTone(440,100);
try { Thread.sleep(1000);
} catch (InterruptedException e) {}
}
}
示例15: playTone
import lejos.hardware.Sound; //导入依赖的package包/类
@Override
public void playTone(int freq, int duration) throws RemoteException {
Sound.playTone(freq, duration);
}