/* source code for demonstration stepper motor design */ /* http://www.mrob.com/lego/stepper.html */ /* */ /* The GNU General Public License version 2.0 applies */ /* to this source code. For more information go to: */ /* http://www.fsf.org/copyleft/copyleft.html */ int i; sub forw { Sleep(1); Fwd(OUT_A, 7); Sleep(9); Off(OUT_A); } task m_forw { forw(); } task m_back { Sleep(1); Rev(OUT_A, 7); Sleep(9); Off(OUT_A); } task m_f8 { i = 8; while(i > 0) { forw(); Sleep(2); i = i - 1; } } task main { while(true) { if (Message() == 1) { stop m_f8; start m_forw; } else if (Message() == 2) { stop m_f8; start m_back; } else if (Message() == 3) { start m_f8; } ClearMessage(); Sleep(1); } }