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@2:70b58ce02820, 2017-05-21 (annotated)
- Committer:
- kryksyh
- Date:
- Sun May 21 14:20:27 2017 +0000
- Revision:
- 2:70b58ce02820
- Parent:
- 1:248129e96f43
- Child:
- 3:bb53fa90af91
License text added
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 | 2:70b58ce02820 | 4 | /* * * * * * * * * * * * * * * * * * * * * * * * |
kryksyh | 2:70b58ce02820 | 5 | |
kryksyh | 2:70b58ce02820 | 6 | Simple 6-LEDs bar library for using with MBed 2.0 library |
kryksyh | 2:70b58ce02820 | 7 | |
kryksyh | 2:70b58ce02820 | 8 | Copyright 2017 Dmitry Makarenko |
kryksyh | 2:70b58ce02820 | 9 | |
kryksyh | 2:70b58ce02820 | 10 | Licensed under the Apache License, Version 2.0 (the "License"); |
kryksyh | 2:70b58ce02820 | 11 | you may not use this file except in compliance with the License. |
kryksyh | 2:70b58ce02820 | 12 | You may obtain a copy of the License at |
kryksyh | 2:70b58ce02820 | 13 | |
kryksyh | 2:70b58ce02820 | 14 | http://www.apache.org/licenses/LICENSE-2.0 |
kryksyh | 2:70b58ce02820 | 15 | |
kryksyh | 2:70b58ce02820 | 16 | Unless required by applicable law or agreed to in writing, software |
kryksyh | 2:70b58ce02820 | 17 | distributed under the License is distributed on an "AS IS" BASIS, |
kryksyh | 2:70b58ce02820 | 18 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kryksyh | 2:70b58ce02820 | 19 | See the License for the specific language governing permissions and |
kryksyh | 2:70b58ce02820 | 20 | limitations under the License. |
kryksyh | 2:70b58ce02820 | 21 | |
kryksyh | 2:70b58ce02820 | 22 | * * * * * * * * * * * * * * * * * * * * * * * * */ |
kryksyh | 2:70b58ce02820 | 23 | |
kryksyh | 0:52b8975f1dd9 | 24 | #include "mbed.h" |
kryksyh | 0:52b8975f1dd9 | 25 | |
kryksyh | 1:248129e96f43 | 26 | |
kryksyh | 2:70b58ce02820 | 27 | /* * * * * * * * * * * * * * * * |
kryksyh | 1:248129e96f43 | 28 | |
kryksyh | 2:70b58ce02820 | 29 | Example using on, off, toggle methods: |
kryksyh | 2:70b58ce02820 | 30 | |
kryksyh | 2:70b58ce02820 | 31 | @code |
kryksyh | 2:70b58ce02820 | 32 | |
kryksyh | 2:70b58ce02820 | 33 | #include "mbed.h" |
kryksyh | 2:70b58ce02820 | 34 | #include "6LedBar.h" |
kryksyh | 2:70b58ce02820 | 35 | |
kryksyh | 2:70b58ce02820 | 36 | |
kryksyh | 2:70b58ce02820 | 37 | LedBar leds (A0, A1, A2, A3, A4, A5); |
kryksyh | 1:248129e96f43 | 38 | |
kryksyh | 2:70b58ce02820 | 39 | int main() { |
kryksyh | 2:70b58ce02820 | 40 | leds.on(0); |
kryksyh | 2:70b58ce02820 | 41 | leds.on(2); |
kryksyh | 2:70b58ce02820 | 42 | leds.on(4); |
kryksyh | 2:70b58ce02820 | 43 | |
kryksyh | 2:70b58ce02820 | 44 | while(true) { |
kryksyh | 2:70b58ce02820 | 45 | for(int i = 0; i < 6; i++) { |
kryksyh | 2:70b58ce02820 | 46 | leds.toggle(i); |
kryksyh | 2:70b58ce02820 | 47 | } |
kryksyh | 2:70b58ce02820 | 48 | wait(0.5); |
kryksyh | 2:70b58ce02820 | 49 | } |
kryksyh | 2:70b58ce02820 | 50 | } |
kryksyh | 2:70b58ce02820 | 51 | |
kryksyh | 2:70b58ce02820 | 52 | |
kryksyh | 2:70b58ce02820 | 53 | @endcode |
kryksyh | 2:70b58ce02820 | 54 | |
kryksyh | 2:70b58ce02820 | 55 | * * * * * * * * * * * * * * * * * * * * * * * * |
kryksyh | 2:70b58ce02820 | 56 | |
kryksyh | 2:70b58ce02820 | 57 | Example using mask methods: |
kryksyh | 1:248129e96f43 | 58 | |
kryksyh | 1:248129e96f43 | 59 | @code |
kryksyh | 1:248129e96f43 | 60 | |
kryksyh | 1:248129e96f43 | 61 | #include "mbed.h" |
kryksyh | 1:248129e96f43 | 62 | #include "6LedBar.h" |
kryksyh | 1:248129e96f43 | 63 | |
kryksyh | 1:248129e96f43 | 64 | |
kryksyh | 1:248129e96f43 | 65 | LedBar leds (A0, A1, A2, A3, A4, A5); |
kryksyh | 1:248129e96f43 | 66 | |
kryksyh | 1:248129e96f43 | 67 | int main() { |
kryksyh | 1:248129e96f43 | 68 | |
kryksyh | 1:248129e96f43 | 69 | leds.on_mask(0b010101); |
kryksyh | 1:248129e96f43 | 70 | |
kryksyh | 1:248129e96f43 | 71 | while(true) { |
kryksyh | 1:248129e96f43 | 72 | leds.toggle_mask(0b111111); |
kryksyh | 1:248129e96f43 | 73 | wait(0.5); |
kryksyh | 1:248129e96f43 | 74 | } |
kryksyh | 1:248129e96f43 | 75 | } |
kryksyh | 1:248129e96f43 | 76 | |
kryksyh | 1:248129e96f43 | 77 | @endcode |
kryksyh | 1:248129e96f43 | 78 | |
kryksyh | 2:70b58ce02820 | 79 | * * * * * * * * * * * * * * * * * * * * * * * */ |
kryksyh | 1:248129e96f43 | 80 | |
kryksyh | 1:248129e96f43 | 81 | |
kryksyh | 0:52b8975f1dd9 | 82 | class LedBar { |
kryksyh | 0:52b8975f1dd9 | 83 | |
kryksyh | 0:52b8975f1dd9 | 84 | public: |
kryksyh | 1:248129e96f43 | 85 | |
kryksyh | 1:248129e96f43 | 86 | //Constructor, you need to specify pins to which |
kryksyh | 1:248129e96f43 | 87 | //leds are connected |
kryksyh | 0:52b8975f1dd9 | 88 | LedBar(PinName p0, |
kryksyh | 0:52b8975f1dd9 | 89 | PinName p1, |
kryksyh | 0:52b8975f1dd9 | 90 | PinName p2, |
kryksyh | 0:52b8975f1dd9 | 91 | PinName p3, |
kryksyh | 0:52b8975f1dd9 | 92 | PinName p4, |
kryksyh | 0:52b8975f1dd9 | 93 | PinName p5); |
kryksyh | 1:248129e96f43 | 94 | |
kryksyh | 1:248129e96f43 | 95 | // Turn n-s led on |
kryksyh | 1:248129e96f43 | 96 | void on(int n); |
kryksyh | 1:248129e96f43 | 97 | |
kryksyh | 1:248129e96f43 | 98 | //Turn n-s led off |
kryksyh | 1:248129e96f43 | 99 | void off(int n); |
kryksyh | 1:248129e96f43 | 100 | |
kryksyh | 1:248129e96f43 | 101 | //Toggle n-s led |
kryksyh | 1:248129e96f43 | 102 | void toggle(int n); |
kryksyh | 1:248129e96f43 | 103 | |
kryksyh | 1:248129e96f43 | 104 | //Set bit mask |
kryksyh | 1:248129e96f43 | 105 | //i.e. mask 0b000101 will turn on leds 0 and 1, and off all others |
kryksyh | 1:248129e96f43 | 106 | void set_mask(int m); |
kryksyh | 1:248129e96f43 | 107 | |
kryksyh | 1:248129e96f43 | 108 | //Turn on leds specified by bit-mask |
kryksyh | 1:248129e96f43 | 109 | void on_mask(int m); |
kryksyh | 1:248129e96f43 | 110 | |
kryksyh | 1:248129e96f43 | 111 | //Turn off leds specified by bit-mask |
kryksyh | 1:248129e96f43 | 112 | void off_mask(int m); |
kryksyh | 1:248129e96f43 | 113 | |
kryksyh | 1:248129e96f43 | 114 | //Toggle leds specified by bit-mask |
kryksyh | 1:248129e96f43 | 115 | void toggle_mask(int m); |
kryksyh | 1:248129e96f43 | 116 | private: |
kryksyh | 1:248129e96f43 | 117 | static const int LEDS_COUNT = 6; |
kryksyh | 1:248129e96f43 | 118 | DigitalOut l0, l1, l2, l3, l4, l5; |
kryksyh | 1:248129e96f43 | 119 | DigitalOut *m_leds[LEDS_COUNT]; |
kryksyh | 0:52b8975f1dd9 | 120 | |
kryksyh | 0:52b8975f1dd9 | 121 | }; |
kryksyh | 0:52b8975f1dd9 | 122 | |
kryksyh | 0:52b8975f1dd9 | 123 | |
kryksyh | 0:52b8975f1dd9 | 124 | #endif //LED_BAR_H |