Simple Blinky library.
Fork of Blinky by
Blinky.h@2:256c8d48f5e7, 2016-11-08 (annotated)
- Committer:
- mbed_demo
- Date:
- Tue Nov 08 22:10:56 2016 +0000
- Revision:
- 2:256c8d48f5e7
- Parent:
- 0:8fe86312b714
Count times LED was turned on.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sarahmarshy | 0:8fe86312b714 | 1 | /* mbed blinky |
sarahmarshy | 0:8fe86312b714 | 2 | * |
sarahmarshy | 0:8fe86312b714 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
sarahmarshy | 0:8fe86312b714 | 4 | * of this software and associated documentation files (the "Software"), to deal |
sarahmarshy | 0:8fe86312b714 | 5 | * in the Software without restriction, including without limitation the rights |
sarahmarshy | 0:8fe86312b714 | 6 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
sarahmarshy | 0:8fe86312b714 | 7 | * copies of the Software, and to permit persons to whom the Software is |
sarahmarshy | 0:8fe86312b714 | 8 | * furnished to do so, subject to the following conditions: |
sarahmarshy | 0:8fe86312b714 | 9 | * |
sarahmarshy | 0:8fe86312b714 | 10 | * The above copyright notice and this permission notice shall be included in |
sarahmarshy | 0:8fe86312b714 | 11 | * all copies or substantial portions of the Software. |
sarahmarshy | 0:8fe86312b714 | 12 | * |
sarahmarshy | 0:8fe86312b714 | 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
sarahmarshy | 0:8fe86312b714 | 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
sarahmarshy | 0:8fe86312b714 | 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
sarahmarshy | 0:8fe86312b714 | 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
sarahmarshy | 0:8fe86312b714 | 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
sarahmarshy | 0:8fe86312b714 | 18 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
sarahmarshy | 0:8fe86312b714 | 19 | * THE SOFTWARE. |
sarahmarshy | 0:8fe86312b714 | 20 | */ |
sarahmarshy | 0:8fe86312b714 | 21 | #ifndef MBED_BLINKY_H |
sarahmarshy | 0:8fe86312b714 | 22 | #define MBED_BLINKY_H |
sarahmarshy | 0:8fe86312b714 | 23 | #include "mbed.h" |
sarahmarshy | 0:8fe86312b714 | 24 | #include "rtos.h" |
sarahmarshy | 0:8fe86312b714 | 25 | |
sarahmarshy | 0:8fe86312b714 | 26 | /** Interface to start a thread that blinks an LED |
sarahmarshy | 0:8fe86312b714 | 27 | */ |
sarahmarshy | 0:8fe86312b714 | 28 | class Blinky { |
sarahmarshy | 0:8fe86312b714 | 29 | public: |
sarahmarshy | 0:8fe86312b714 | 30 | /** Create a Blinky |
sarahmarshy | 0:8fe86312b714 | 31 | * |
sarahmarshy | 0:8fe86312b714 | 32 | * @param led A PinName, the pin name of the LED to blink |
sarahmarshy | 0:8fe86312b714 | 33 | * @param interval A int, the interval of time between LED blinks |
sarahmarshy | 0:8fe86312b714 | 34 | */ |
sarahmarshy | 0:8fe86312b714 | 35 | Blinky(PinName led, int interval); |
sarahmarshy | 0:8fe86312b714 | 36 | /**Start a thread executing blink_led*/ |
sarahmarshy | 0:8fe86312b714 | 37 | void start(); |
sarahmarshy | 0:8fe86312b714 | 38 | /**Terminate the thread blinking the LED*/ |
sarahmarshy | 0:8fe86312b714 | 39 | void stop(); |
mbed_demo | 2:256c8d48f5e7 | 40 | /**Find the number of times the LED has been blinked */ |
mbed_demo | 2:256c8d48f5e7 | 41 | float times_blinked(); |
sarahmarshy | 0:8fe86312b714 | 42 | |
sarahmarshy | 0:8fe86312b714 | 43 | protected: |
sarahmarshy | 0:8fe86312b714 | 44 | /**Function to blink the LED*/ |
sarahmarshy | 0:8fe86312b714 | 45 | void blink_led(); |
sarahmarshy | 0:8fe86312b714 | 46 | /**Thread to execute blink_led*/ |
sarahmarshy | 0:8fe86312b714 | 47 | Thread _blinker; |
sarahmarshy | 0:8fe86312b714 | 48 | /**LED to blink */ |
sarahmarshy | 0:8fe86312b714 | 49 | DigitalOut _led; |
sarahmarshy | 0:8fe86312b714 | 50 | /**Interval of time between blinks*/ |
sarahmarshy | 0:8fe86312b714 | 51 | int _interval; |
sarahmarshy | 0:8fe86312b714 | 52 | /**Bool to stop blinking LED */ |
sarahmarshy | 0:8fe86312b714 | 53 | bool stop_blink; |
mbed_demo | 2:256c8d48f5e7 | 54 | /**Count of times LED blinked */ |
mbed_demo | 2:256c8d48f5e7 | 55 | float led_count; |
sarahmarshy | 0:8fe86312b714 | 56 | }; |
sarahmarshy | 0:8fe86312b714 | 57 | #endif |
sarahmarshy | 0:8fe86312b714 | 58 | |
sarahmarshy | 0:8fe86312b714 | 59 |