2011-11-10 36 views
0

我正在使用IOIO Android開發板。我試圖控制2個引腳和一個LED,並在間隔時間內關閉它們。到目前爲止,它連接良好,LED和引腳開啓和關閉,但沒有正確的時間。我認爲問題與sleep()函數有關。 任何幫助或指導,將不勝感激。儘管使用睡眠時間錯誤

    class IOIOThread extends Thread { 
     private IOIO ioio_; 
     private boolean abort_ = false; 


     @Override 
     public void run() { 
      super.run(); 
      while (true) { 
       synchronized (this) { 
        if (abort_) { 
         break; 
        } 
        ioio_ = IOIOFactory.create(); 
       } 
       try { 
        setText(R.string.wait_ioio); 
        ioio_.waitForConnect(); 
        setText(R.string.ioio_connected); 

        while (true) { 

         while((button_.isChecked())==true){ 

          DigitalOutput led = ioio_.openDigitalOutput(0, false);; 
          DigitalOutput S1 = ioio_.openDigitalOutput(35, false); 
          DigitalOutput S2 = ioio_.openDigitalOutput(36, false); 
          DigitalOutput S3 = ioio_.openDigitalOutput(37, false); 
          DigitalOutput S4 = ioio_.openDigitalOutput(38, false); 

          holdTime=30000; 

          for (currentTime=0; currentTime<=holdTime;) 
          { 
           led.write(true); 
           S1.write(true); 
           S2.write(true); 
           sleep(4000); 
           led.write(false); 
           S1.write(false); 
           S2.write(false); 
           sleep(2000); 
           led.write(true); 
           S3.write(true); 
           S4.write(true); 
           sleep(4000); 
           led.write(false); 
           S3.write(false); 
           S4.write(false); 
           sleep(4000); 
           currentTime = currentTime+14000; 

         }}}} 

       catch (ConnectionLostException e) { 
       } catch (Exception e) { 
        Log.e("HelloIOIOPower", "Unexpected exception caught", e); 
        ioio_.disconnect(); 
        break; 
       } finally { 
        try { 
         ioio_.waitForDisconnect(); 
        } catch (InterruptedException e) { 
        } 
       } 
      } 
     } 
+0

那麼問題是什麼?你期望什麼時機,你看到了什麼? –

+0

你能描述一下你打算做什麼以及它在做什麼? – corsiKa

回答

1

Sleep()不是實時的 - 它只是讓您的線程保持至少指定的毫秒數。之後,它可用於安排並將在某個時間執行。