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

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

Committer:
kryksyh
Date:
Sun May 21 14:29:24 2017 +0000
Revision:
3:bb53fa90af91
Parent:
2:70b58ce02820
Child:
4:ecb39b6f0e18
Doxygen docs

Who changed what in which revision?

UserRevisionLine numberNew 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 3:bb53fa90af91 28 /**
kryksyh 3:bb53fa90af91 29 * LedBar class is used for controlling 6 led bar.
kryksyh 3:bb53fa90af91 30 *
kryksyh 3:bb53fa90af91 31 * Example using on, off, toggle methods:
kryksyh 3:bb53fa90af91 32 *
kryksyh 3:bb53fa90af91 33 *@code
kryksyh 3:bb53fa90af91 34 *
kryksyh 3:bb53fa90af91 35 * #include "mbed.h"
kryksyh 3:bb53fa90af91 36 * #include "6LedBar.h"
kryksyh 3:bb53fa90af91 37 *
kryksyh 3:bb53fa90af91 38 *
kryksyh 3:bb53fa90af91 39 * LedBar leds (A0, A1, A2, A3, A4, A5);
kryksyh 3:bb53fa90af91 40 *
kryksyh 3:bb53fa90af91 41 * int main() {
kryksyh 3:bb53fa90af91 42 * leds.on(0);
kryksyh 3:bb53fa90af91 43 * leds.on(2);
kryksyh 3:bb53fa90af91 44 * leds.on(4);
kryksyh 3:bb53fa90af91 45 *
kryksyh 3:bb53fa90af91 46 * while(true) {
kryksyh 3:bb53fa90af91 47 * for(int i = 0; i < 6; i++) {
kryksyh 3:bb53fa90af91 48 * leds.toggle(i);
kryksyh 3:bb53fa90af91 49 * }
kryksyh 3:bb53fa90af91 50 * wait(0.5);
kryksyh 3:bb53fa90af91 51 * }
kryksyh 3:bb53fa90af91 52 * }
kryksyh 3:bb53fa90af91 53 *
kryksyh 3:bb53fa90af91 54 *
kryksyh 3:bb53fa90af91 55 *@endcode
kryksyh 3:bb53fa90af91 56 *
kryksyh 3:bb53fa90af91 57 * * * * * * * * * * * * * * * * * * * * * * * * *
kryksyh 3:bb53fa90af91 58 *
kryksyh 3:bb53fa90af91 59 * Example using mask methods:
kryksyh 3:bb53fa90af91 60 *
kryksyh 3:bb53fa90af91 61 *@code
kryksyh 3:bb53fa90af91 62 *
kryksyh 3:bb53fa90af91 63 * #include "mbed.h"
kryksyh 3:bb53fa90af91 64 * #include "6LedBar.h"
kryksyh 3:bb53fa90af91 65 *
kryksyh 3:bb53fa90af91 66 *
kryksyh 3:bb53fa90af91 67 * LedBar leds (A0, A1, A2, A3, A4, A5);
kryksyh 3:bb53fa90af91 68 *
kryksyh 3:bb53fa90af91 69 * int main() {
kryksyh 3:bb53fa90af91 70 *
kryksyh 3:bb53fa90af91 71 * leds.on_mask(0b010101);
kryksyh 3:bb53fa90af91 72 *
kryksyh 3:bb53fa90af91 73 * while(true) {
kryksyh 3:bb53fa90af91 74 * leds.toggle_mask(0b111111);
kryksyh 3:bb53fa90af91 75 * wait(0.5);
kryksyh 3:bb53fa90af91 76 * }
kryksyh 3:bb53fa90af91 77 * }
kryksyh 3:bb53fa90af91 78 *
kryksyh 3:bb53fa90af91 79 *@endcode
kryksyh 3:bb53fa90af91 80 *
kryksyh 3:bb53fa90af91 81 **/
kryksyh 1:248129e96f43 82
kryksyh 3:bb53fa90af91 83 //!
kryksyh 0:52b8975f1dd9 84 class LedBar {
kryksyh 0:52b8975f1dd9 85
kryksyh 0:52b8975f1dd9 86 public:
kryksyh 1:248129e96f43 87
kryksyh 1:248129e96f43 88 //Constructor, you need to specify pins to which
kryksyh 1:248129e96f43 89 //leds are connected
kryksyh 0:52b8975f1dd9 90 LedBar(PinName p0,
kryksyh 0:52b8975f1dd9 91 PinName p1,
kryksyh 0:52b8975f1dd9 92 PinName p2,
kryksyh 0:52b8975f1dd9 93 PinName p3,
kryksyh 0:52b8975f1dd9 94 PinName p4,
kryksyh 0:52b8975f1dd9 95 PinName p5);
kryksyh 1:248129e96f43 96
kryksyh 3:bb53fa90af91 97 //! Turn n-s led on
kryksyh 1:248129e96f43 98 void on(int n);
kryksyh 1:248129e96f43 99
kryksyh 3:bb53fa90af91 100 //! Turn n-s led off
kryksyh 1:248129e96f43 101 void off(int n);
kryksyh 1:248129e96f43 102
kryksyh 3:bb53fa90af91 103 //! Toggle n-s led
kryksyh 1:248129e96f43 104 void toggle(int n);
kryksyh 1:248129e96f43 105
kryksyh 3:bb53fa90af91 106 //! Set bit mask
kryksyh 1:248129e96f43 107 //i.e. mask 0b000101 will turn on leds 0 and 1, and off all others
kryksyh 1:248129e96f43 108 void set_mask(int m);
kryksyh 1:248129e96f43 109
kryksyh 3:bb53fa90af91 110 //! Turn on leds specified by bit-mask
kryksyh 1:248129e96f43 111 void on_mask(int m);
kryksyh 1:248129e96f43 112
kryksyh 3:bb53fa90af91 113 //! Turn off leds specified by bit-mask
kryksyh 1:248129e96f43 114 void off_mask(int m);
kryksyh 1:248129e96f43 115
kryksyh 3:bb53fa90af91 116 //! Toggle leds specified by bit-mask
kryksyh 1:248129e96f43 117 void toggle_mask(int m);
kryksyh 1:248129e96f43 118 private:
kryksyh 1:248129e96f43 119 static const int LEDS_COUNT = 6;
kryksyh 1:248129e96f43 120 DigitalOut l0, l1, l2, l3, l4, l5;
kryksyh 1:248129e96f43 121 DigitalOut *m_leds[LEDS_COUNT];
kryksyh 0:52b8975f1dd9 122
kryksyh 0:52b8975f1dd9 123 };
kryksyh 0:52b8975f1dd9 124
kryksyh 0:52b8975f1dd9 125
kryksyh 0:52b8975f1dd9 126 #endif //LED_BAR_H