Arduino Protothreads by Example I am trying to get Arduino working with Protothreads and wanted to confirm I have the basic setup correct. If I have understood the API correctly, then the following code should be what I need to start 2 concurrent threads from inside an Arduino program:

#include &lt;pt.h&gt;

static struct pt t1, t2;

void setup() {
    PT_INIT(&amp;t1);
    PT_INIT(&amp;t2);
}

void loop() {
    doSomething(&amp;t1, 500);
    doSomethingElse(&amp;t2, 500);
}

static int doSomething(struct pt *pt, int interval) {
    PT_BEGIN(pt);
    sleep(100);
    PT_END(pt);
}

static int doSomethingElse(struct pt *pt, int interval) {
    PT_BEGIN(pt);
    sleep(250);
    PT_END(pt);
}


Does anyone see anything that jumps out at them as missing or wrong?
Check this example: rather than sleep(), it uses PT_WAIT_UNTIL

  while(1) {
      PT_WAIT_UNTIL(pt, millis() - timestamp &gt; interval );
      timestamp = millis();
      doSomething();
  }


That should be the proto-thread way of waiting: PT_WAIT_UNTIL will make sure that your thread sleeps in a way that allows other threads to run.

The rest looks fine, but I have not tried to run the code.