Shop OBEX P1 Docs P2 Docs Learn Events
Running methods simultaneously? — Parallax Forums

Running methods simultaneously?

bulkheadbulkhead Posts: 405
edited 2005-12-05 07:01 in General Discussion
I have two methods- an "openRightArm()" and an "openLeftArm()" method, which increments PWM values in millisecond intervals to a servo, opening the arm in a period of roughly two seconds. Is there a way to get these two methods to run at the same time? Or do I have to combine the two methods into one so that both PWMs are updated in the same loop?

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2005-12-05 07:01
    Your best option is to update both in the same loop, using a timer.

    static Timer t = new Timer();
    static boolean armUpdate; //set this boolean when arms need update

    static void main() {
    · if (armUpdate) {
    ··· if (t.timeout(1)) { //1 msec timeout
    ····· t.mark();
    ····· updateLeftArm();
    ····· updateRightArm();
    ··· }
    · }
    · //other mainloop code here
    }

    regards peter
Sign In or Register to comment.