import utmech.mechanompu.io.*; import utmech.mechanompu.*; public class speaker { private static int period=5; //周期 private static final int unit_time=1; private static final int speaker_address=0xfffa19; private static final byte speaker_on=7; private static final byte speaker_off=0; public static void main(String arg[]) { System.out.println("Period="+period); //最初のスピードを表示 while(true) { // キーの押し下げ状態の読みとり int key_code=key.scan(); if(key_code==key.f1) //F1が押されていたら break; // 終了 if(key_code >= 0 && key_code <= 0x0f) { //0からFだったら period=key_code; // 周期を変更 System.out.println("Period="+period); } // try { memory.poke(speaker_address, speaker_on); Thread.sleep(period*unit_time); //引数[ms](以上)実行を停止する memory.poke(speaker_address, speaker_off); Thread.sleep(period*unit_time); } //sleepで発生の可能性のある例外を捕捉 catch(InterruptedException e) { System.out.println(e); } } } }