You are viewing an older revision! See the latest version

Writing a Library

Writing a Library

This page discusses the steps in writing and publishing an mbed Library.

What is a Library

A library is a collection of code, usually focused on enabling a specific component, peripheral or .

It is effectively a collection of functions and classes, without a "main()" program.

main.cpp

#include "mbed.h"

class Flasher {
public:
    Flasher(PinName pin) : _pin(pin) {
        _pin = 0;
    }

    void flash(int n) {
        for(int i=0; i<n*2; n++) {
            _pin = !_pin;
            wait(0.2);
        }
    }

    DigitalOut _pin;
};

Flasher led(LED2);

int main() {
    led.flash(5);
}

All wikipages