2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

leJOSのStopwatchクラスの使い方サンプル

Last updated at Posted at 2016-06-19
StopwatchSample.java
import lejos.hardware.Button;
import lejos.hardware.Sound;
import lejos.utility.Delay;
import lejos.utility.Stopwatch;

public class StopwatchSample {

	public static void main(String[] args) {
		Stopwatch stopwatch = new Stopwatch();		// インスタンスを作ると時間の計測が始まる

		System.out.println(stopwatch.elapsed());	// 経過時間を取得
		Delay.msDelay(3000);						// 3000ミリ秒待つ
		System.out.println(stopwatch.elapsed());	// 待っている間も時間の計測をしている

		stopwatch.reset();  						// 経過時間をリセット
		System.out.println(stopwatch.elapsed());
		while (true) {
			Delay.msDelay(1000);						
			System.out.println(stopwatch.elapsed());

			if (stopwatch.elapsed() % (5 * 1000) < 1000) {
				// 5秒毎に音を鳴らす
				Sound.beep();
			}
			if (stopwatch.elapsed() > 30 * 1000) {
				// 30秒経過したらループを抜ける
				break;
			}
		}
		
		System.out.println("push any button");
		Button.waitForAnyPress();	// 何かボタンが押されるまで待つ
	}

}

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?