Simple 6-LED bar library. Provides some useful functions.

Simple 6 leds bar library. It allows you to control individual leds, and provides masks.

6LedBar.h

Committer:
kryksyh
Date:
2017-05-21
Revision:
1:248129e96f43
Parent:
0:52b8975f1dd9
Child:
2:70b58ce02820

File content as of revision 1:248129e96f43:

#ifndef LED_BAR_H
#define LED_BAR_H

#include "mbed.h"



/*

Example:

@code

#include "mbed.h"
#include "6LedBar.h"


LedBar leds (A0, A1, A2, A3, A4, A5);

int main() {

    leds.on_mask(0b010101);
    
    while(true) {
        leds.toggle_mask(0b111111);
        wait(0.5);
    }
}

@endcode

*/


class LedBar {

public:

    //Constructor, you need to specify pins to which
    //leds are connected
    LedBar(PinName p0,
           PinName p1,
           PinName p2,
           PinName p3,
           PinName p4,
           PinName p5);
           
    // Turn n-s led on
    void on(int n);
    
    //Turn n-s led off
    void off(int n);
    
    //Toggle n-s led
    void toggle(int n);
    
    //Set bit mask
    //i.e. mask 0b000101 will turn on leds 0 and 1, and off all others
    void set_mask(int m);
    
    //Turn on leds specified by bit-mask
    void on_mask(int m);
    
    //Turn off leds specified by bit-mask
    void off_mask(int m);
    
    //Toggle leds specified by bit-mask
    void toggle_mask(int m);
private:
    static const int LEDS_COUNT = 6;
    DigitalOut l0, l1, l2, l3, l4, l5;
    DigitalOut *m_leds[LEDS_COUNT];

};


#endif //LED_BAR_H