Hello,
I think you misunderstand how some of the library API works, and you should
carefully read the doc again.
calling setSpeed(0) is probably not appropriate for what you want. It is for
use with runSpeed().
Calling moveTo() frequently in the loop is unnecessary and inefficient. Call it
only when you have a new target position.
Calling runToNewPosition() followed by run() is strange. runToNewPosition()
blocks until it reaches the new position. From the doc: "Dont use this in
event loops, since it blocks.".
The general strategy for accelstepper is to always call run() as often as
possible (ie every time through the main loop), and (only very occasionally)
call other api functions to change/set position when external events occur.
You probably want something like this:
loop()
{
if (have new target from matlab)
moveTo(newtarget)
if (have hit negative limit)
setCurrentPosition(minimumposition)
if (have hit positive limit)
setCurrentPosition(maximumposition)
run();
}
also you probably need to consider what happens with limit switch bounces.
Cheers.
--
Mike McCauley VK4AMM
mi...@airspayce.com
Airspayce Pty Ltd 9 Bulbul Place Currumbin Waters QLD 4223 Australia
http://www.airspayce.com
Phone
+61 7 5598-7474 Fax
+61 7 5598-7070