# speed3.cpp

This sketch creates a reflex that modifies its Processor speed. See SFBProcessor::setCode() for warnings and limitations of this sort of on-the-fly speed changing!

Note that at 12MHz, the board cannot reliably handle baud rates above about 115KB. If you connect at a faster speed and then send an 's12' packet, most likely serial communications will be disrupted (sooner or later), triggering a new baud rate negotiation, during which a slower baud rate will be chosen.

    void handleSpeed(u8 * packet) {
      u32 mhz;
      if (packetScanf(packet,"s%d\n",&mhz) != 3) return; // Ignore bad format
      if (mhz < 12 || mhz > 72) return;                  // Ignore bad speed
      Processor.setMHz(mhz);        // Change the processor speed!
    }

    void setup() {
      Body.reflex('s',handleSpeed); // Create reflex
    }

    void loop() {
      ledOn(BODY_RGB_GREEN_PIN);    // Blink with 1sec period
      delay(500);                   // (Note that the blink period
      ledOff(BODY_RGB_GREEN_PIN);   // is unaffected by processor
      delay(500);                   // speed!  A ms remains a ms!)
      println(Processor.getMHz());  // And report current speed
    }