Junichi Katsu / Milkcocoa-os

Dependents:   mbed-os-example-wifi-milkcocoa MilkcocoaOsSample_Eth MilkcocoaOsSample_ESP8266 MilkcocoaOsSample_Eth_DigitalIn

Embed: (wiki syntax)

« Back to documentation index

FP Class Reference

FP Class Reference

Example using the FP Class with global functions. More...

#include <FP.h>


Detailed Description

Example using the FP Class with global functions.

  #include "mbed.h"
  #include "FP.h"

  FP<void,bool>fp;
  DigitalOut myled(LED1);

  void handler(bool value)
  {
      myled = value;
      return;
  }

  int main()
  {
      fp.attach(&handler);

      while(1)
      {
          fp(1);
          wait(0.2);
          fp(0);
          wait(0.2);
      }
  }

Example using the FP Class with different class member functions

  #include "mbed.h"
  #include "FP.h"

  FP<void,bool>fp;
  DigitalOut myled(LED4);

  class Wrapper
  {
  public:
      Wrapper(){}

      void handler(bool value)
      {
          myled = value;
          return;
      }
  };

  int main()
  {
      Wrapper wrapped;
      fp.attach(&wrapped, &Wrapper::handler);

      while(1)
      {
          fp(1);
          wait(0.2);
          fp(0);
          wait(0.2);
      }
  }

Example using the FP Class with member FP and member function

  #include "mbed.h"
  #include "FP.h"

  DigitalOut myled(LED2);

  class Wrapper
  {
  public:
      Wrapper()
      {
          fp.attach(this, &Wrapper::handler);
      }

      void handler(bool value)
      {
          myled = value;
          return;
      }

      FP<void,bool>fp;
  };

  int main()
  {
      Wrapper wrapped;

      while(1)
      {
          wrapped.fp(1);
          wait(0.2);
          wrapped.fp(0);
          wait(0.2);
      }
  }

API for managing Function Pointers