Info

この質問は閉じられています。 編集または回答するには再度開いてください。

I'm attempting to get something to perform only for a certain amount of time. Is there a function for this?

1 回表示 (過去 30 日間)
Jaime Juarez
Jaime Juarez 2016 年 4 月 16 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I'm trying to get part of my program to execute for only half a second. I have the following code..
case 'backward'
display('Going Backwards')
Portarduino.analogWrite(rspeed,50);
Portarduino.analogWrite(lspeed,50);
Portarduino.digitalWrite(rdir,1);
Portarduino.digitalWrite(ldir,1);
pause(0.00001)
robotstatus='mainloop'
And I only want this to perform for .5 seconds. Can someone give me some guidance? Thank you!
  2 件のコメント
Ced
Ced 2016 年 4 月 16 日
Have you tried using tic and toc? I don't have the hardware, so I can't check, but I could image that something like this might work:
% --> Get command to drive backwards for 5 seconds
display('Going Backwards')
tic
while ( toc < 5 )
Portarduino.analogWrite(rspeed,50);
Portarduino.analogWrite(lspeed,50);
Portarduino.digitalWrite(rdir,1);
Portarduino.digitalWrite(ldir,1);
pause(0.00001)
robotstatus='mainloop'
end
PS: What is the sampling rate of your Arduino? 0.00001 seems unnecessarily fast to me.
Jaime Juarez
Jaime Juarez 2016 年 4 月 21 日
This happened to work once I made the pause, slower. Thank you so much!

回答 (0 件)

この質問は閉じられています。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by