// qled sketch 1: Demo blinking LEDs without blocking packet handling

void doIt(u8 *packet) {
  // Get the face led where the packet came from.
  u32 led = pinInFace(FACE_LED_PIN, packetSource(packet)); 

  for (u32 i = 0; i < 3; ++i) { // Blink source face three times fast
    QLED.on(led, 100);          // Schedule about 100ms on..
    QLED.off(led, 100);         // and then about 100ms off.
  }

  if (random(10)!=0)            // 9 times out of 10
    facePrintln(random(NORTH,WEST+1),packet,packetLength(packet)); // pass it on
  else {                        // 1 time out of 10
    QLED.off(BODY_RGB_RED_PIN, 400); // Red off for about 400ms, then
    QLED.on(BODY_RGB_RED_PIN, 200);  // Red on for about 200ms, then
    QLED.off(BODY_RGB_RED_PIN, 0);   // Leave red turned off
  }
}

void setup() {
  QLED.begin();                // Init the LED queueing system!
  Body.reflex('p',doIt);       // Create a reflex
}

void loop() { 
  delay(100);                  // loop about 10 times per second
  if (random(30)==0)           // about 1 in 30 loops (about 3 seconds)
    facePrintln(random(NORTH,WEST+1),"p"); // send a 'p' to a random neighbor
}                                          // (who might or might not exist..)
