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@1:248129e96f43, 2017-05-21 (annotated)
- Committer:
- kryksyh
- Date:
- Sun May 21 14:07:51 2017 +0000
- Revision:
- 1:248129e96f43
- Parent:
- 0:52b8975f1dd9
- Child:
- 2:70b58ce02820
add some docs, and set_mask method
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kryksyh | 0:52b8975f1dd9 | 1 | #ifndef LED_BAR_H |
kryksyh | 0:52b8975f1dd9 | 2 | #define LED_BAR_H |
kryksyh | 0:52b8975f1dd9 | 3 | |
kryksyh | 0:52b8975f1dd9 | 4 | #include "mbed.h" |
kryksyh | 0:52b8975f1dd9 | 5 | |
kryksyh | 1:248129e96f43 | 6 | |
kryksyh | 1:248129e96f43 | 7 | |
kryksyh | 1:248129e96f43 | 8 | /* |
kryksyh | 1:248129e96f43 | 9 | |
kryksyh | 1:248129e96f43 | 10 | Example: |
kryksyh | 1:248129e96f43 | 11 | |
kryksyh | 1:248129e96f43 | 12 | @code |
kryksyh | 1:248129e96f43 | 13 | |
kryksyh | 1:248129e96f43 | 14 | #include "mbed.h" |
kryksyh | 1:248129e96f43 | 15 | #include "6LedBar.h" |
kryksyh | 1:248129e96f43 | 16 | |
kryksyh | 1:248129e96f43 | 17 | |
kryksyh | 1:248129e96f43 | 18 | LedBar leds (A0, A1, A2, A3, A4, A5); |
kryksyh | 1:248129e96f43 | 19 | |
kryksyh | 1:248129e96f43 | 20 | int main() { |
kryksyh | 1:248129e96f43 | 21 | |
kryksyh | 1:248129e96f43 | 22 | leds.on_mask(0b010101); |
kryksyh | 1:248129e96f43 | 23 | |
kryksyh | 1:248129e96f43 | 24 | while(true) { |
kryksyh | 1:248129e96f43 | 25 | leds.toggle_mask(0b111111); |
kryksyh | 1:248129e96f43 | 26 | wait(0.5); |
kryksyh | 1:248129e96f43 | 27 | } |
kryksyh | 1:248129e96f43 | 28 | } |
kryksyh | 1:248129e96f43 | 29 | |
kryksyh | 1:248129e96f43 | 30 | @endcode |
kryksyh | 1:248129e96f43 | 31 | |
kryksyh | 1:248129e96f43 | 32 | */ |
kryksyh | 1:248129e96f43 | 33 | |
kryksyh | 1:248129e96f43 | 34 | |
kryksyh | 0:52b8975f1dd9 | 35 | class LedBar { |
kryksyh | 0:52b8975f1dd9 | 36 | |
kryksyh | 0:52b8975f1dd9 | 37 | public: |
kryksyh | 1:248129e96f43 | 38 | |
kryksyh | 1:248129e96f43 | 39 | //Constructor, you need to specify pins to which |
kryksyh | 1:248129e96f43 | 40 | //leds are connected |
kryksyh | 0:52b8975f1dd9 | 41 | LedBar(PinName p0, |
kryksyh | 0:52b8975f1dd9 | 42 | PinName p1, |
kryksyh | 0:52b8975f1dd9 | 43 | PinName p2, |
kryksyh | 0:52b8975f1dd9 | 44 | PinName p3, |
kryksyh | 0:52b8975f1dd9 | 45 | PinName p4, |
kryksyh | 0:52b8975f1dd9 | 46 | PinName p5); |
kryksyh | 1:248129e96f43 | 47 | |
kryksyh | 1:248129e96f43 | 48 | // Turn n-s led on |
kryksyh | 1:248129e96f43 | 49 | void on(int n); |
kryksyh | 1:248129e96f43 | 50 | |
kryksyh | 1:248129e96f43 | 51 | //Turn n-s led off |
kryksyh | 1:248129e96f43 | 52 | void off(int n); |
kryksyh | 1:248129e96f43 | 53 | |
kryksyh | 1:248129e96f43 | 54 | //Toggle n-s led |
kryksyh | 1:248129e96f43 | 55 | void toggle(int n); |
kryksyh | 1:248129e96f43 | 56 | |
kryksyh | 1:248129e96f43 | 57 | //Set bit mask |
kryksyh | 1:248129e96f43 | 58 | //i.e. mask 0b000101 will turn on leds 0 and 1, and off all others |
kryksyh | 1:248129e96f43 | 59 | void set_mask(int m); |
kryksyh | 1:248129e96f43 | 60 | |
kryksyh | 1:248129e96f43 | 61 | //Turn on leds specified by bit-mask |
kryksyh | 1:248129e96f43 | 62 | void on_mask(int m); |
kryksyh | 1:248129e96f43 | 63 | |
kryksyh | 1:248129e96f43 | 64 | //Turn off leds specified by bit-mask |
kryksyh | 1:248129e96f43 | 65 | void off_mask(int m); |
kryksyh | 1:248129e96f43 | 66 | |
kryksyh | 1:248129e96f43 | 67 | //Toggle leds specified by bit-mask |
kryksyh | 1:248129e96f43 | 68 | void toggle_mask(int m); |
kryksyh | 1:248129e96f43 | 69 | private: |
kryksyh | 1:248129e96f43 | 70 | static const int LEDS_COUNT = 6; |
kryksyh | 1:248129e96f43 | 71 | DigitalOut l0, l1, l2, l3, l4, l5; |
kryksyh | 1:248129e96f43 | 72 | DigitalOut *m_leds[LEDS_COUNT]; |
kryksyh | 0:52b8975f1dd9 | 73 | |
kryksyh | 0:52b8975f1dd9 | 74 | }; |
kryksyh | 0:52b8975f1dd9 | 75 | |
kryksyh | 0:52b8975f1dd9 | 76 | |
kryksyh | 0:52b8975f1dd9 | 77 | #endif //LED_BAR_H |