0
zhan ting

想试着用光电门来控制小车中断,用了以下代码(部分),但是不知道为什么没有用,是否一定要像示例interruptCtrlLed一样?

void countRotationRight()
{
if(millis()-lastTimeR>10)
{
lastTimeR = millis();
countR++;
if(countL<=countR)
{
motorR.stop();
motorL.run(speedL);
}
}
}

void goRight()
{
speedL = (speedL>0)?speedL:-speedL;
countR = 99999;
countL = 0;
attachInterrupt(0,countRotationLeft,FALLING);
motorL.run(speedL*.8);
}

void goStop()
{
detachInterrupt(0);
detachInterrupt(1);
motorL.stop();
motorR.stop();
}

sean 回答了