Java 尽管使用了睡眠,但时间安排错误
我在IOIO安卓开发板工作。我试着控制2个引脚和一个led,并每隔一段时间开关它们。到目前为止,它连接良好,led和引脚正在打开和关闭,但没有正确的时间。我认为问题在于sleep()函数。 任何帮助或指导都将不胜感激Java 尽管使用了睡眠,但时间安排错误,java,android,sleep,thread-sleep,Java,Android,Sleep,Thread Sleep,我在IOIO安卓开发板工作。我试着控制2个引脚和一个led,并每隔一段时间开关它们。到目前为止,它连接良好,led和引脚正在打开和关闭,但没有正确的时间。我认为问题在于sleep()函数。 任何帮助或指导都将不胜感激 class IOIOThread extends Thread { private IOIO ioio_; private boolean abort_ = false; @Override
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) {
}
}
}
}
类IOIOThread扩展线程{
私人IOIOIOU;
私有布尔中止=false;
@凌驾
公开募捐{
super.run();
while(true){
已同步(此){
如果(中止){
打破
}
ioio=iofactory.create();
}
试一试{
setText(R.string.wait_ioo);
ioio_.waitForConnect();
setText(R.string.iou连接);
while(true){
while((按钮检查())==true){
DigitalOutput发光二极管=ioio_10;openDigitalOutput(0,假);;
DigitalOutput S1=ioio_u2;openDigitalOutput(35,false);
DigitalOutput S2=ioio_u2;openDigitalOutput(36,false);
DigitalOutput S3=ioio_u2;openDigitalOutput(37,false);
DigitalOutput S4=ioio_u2;openDigitalOutput(38,假);
保持时间=30000;
对于(currentTime=0;currentTimeSleep()不是实时的-它只是将线程挂起至少指定的毫秒数。之后,它可用于调度,并将在某个时间执行。那么问题出在哪里?您期望的是什么时间,您看到的是什么?您能描述一下您打算做什么,以及它正在做什么吗?