Diana Saveh
/
led
Library A: LED library to controll the led on the Happy Gecko.
LED.h@1:55b5e6d28fb3, 2018-02-12 (annotated)
- Committer:
- diana_s
- Date:
- Mon Feb 12 21:40:22 2018 +0000
- Revision:
- 1:55b5e6d28fb3
- Parent:
- 0:3cabc617d433
updated doc;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
diana_s | 0:3cabc617d433 | 1 | #ifndef MBED_LED_H |
diana_s | 0:3cabc617d433 | 2 | #define MBED_LED_H |
diana_s | 0:3cabc617d433 | 3 | |
diana_s | 0:3cabc617d433 | 4 | #include "mbed.h" |
diana_s | 0:3cabc617d433 | 5 | |
diana_s | 0:3cabc617d433 | 6 | |
diana_s | 0:3cabc617d433 | 7 | /** LED class. |
diana_s | 0:3cabc617d433 | 8 | * To use the library, its header file needs to be included and an object of the LED class created. |
diana_s | 1:55b5e6d28fb3 | 9 | |
diana_s | 1:55b5e6d28fb3 | 10 | * Example: Turns the LED0 on. |
diana_s | 1:55b5e6d28fb3 | 11 | * @code |
diana_s | 1:55b5e6d28fb3 | 12 | * #include "mbed.h" |
diana_s | 1:55b5e6d28fb3 | 13 | * #include "LED.h" |
diana_s | 1:55b5e6d28fb3 | 14 | * |
diana_s | 1:55b5e6d28fb3 | 15 | * LED gpio(LED0); |
diana_s | 1:55b5e6d28fb3 | 16 | * |
diana_s | 1:55b5e6d28fb3 | 17 | * int main() { |
diana_s | 1:55b5e6d28fb3 | 18 | * gpio.ledOn(); |
diana_s | 1:55b5e6d28fb3 | 19 | * } |
diana_s | 0:3cabc617d433 | 20 | |
diana_s | 0:3cabc617d433 | 21 | * @endcode |
diana_s | 1:55b5e6d28fb3 | 22 | |
diana_s | 1:55b5e6d28fb3 | 23 | * Example2: Toggles the LED on and off. |
diana_s | 1:55b5e6d28fb3 | 24 | * @code |
diana_s | 1:55b5e6d28fb3 | 25 | * #include "mbed.h" |
diana_s | 1:55b5e6d28fb3 | 26 | * #include "LED.h" |
diana_s | 1:55b5e6d28fb3 | 27 | * |
diana_s | 1:55b5e6d28fb3 | 28 | * LED gpio(LED0); |
diana_s | 1:55b5e6d28fb3 | 29 | * |
diana_s | 1:55b5e6d28fb3 | 30 | * int main() { |
diana_s | 1:55b5e6d28fb3 | 31 | * gpio.toggle(); |
diana_s | 1:55b5e6d28fb3 | 32 | * wait(0.2); |
diana_s | 1:55b5e6d28fb3 | 33 | * gpio.toggle(); |
diana_s | 1:55b5e6d28fb3 | 34 | * wait(0.2); |
diana_s | 1:55b5e6d28fb3 | 35 | * } |
diana_s | 1:55b5e6d28fb3 | 36 | |
diana_s | 1:55b5e6d28fb3 | 37 | * @endcode |
diana_s | 1:55b5e6d28fb3 | 38 | |
diana_s | 0:3cabc617d433 | 39 | */ |
diana_s | 0:3cabc617d433 | 40 | |
diana_s | 0:3cabc617d433 | 41 | |
diana_s | 0:3cabc617d433 | 42 | class LED { |
diana_s | 0:3cabc617d433 | 43 | public: |
diana_s | 0:3cabc617d433 | 44 | /** The constructor creates an instance of the LED class. It is automatically called when a new object is declared. |
diana_s | 0:3cabc617d433 | 45 | */ |
diana_s | 0:3cabc617d433 | 46 | LED(PinName pin); |
diana_s | 0:3cabc617d433 | 47 | /** This function turns led on. |
diana_s | 0:3cabc617d433 | 48 | */ |
diana_s | 0:3cabc617d433 | 49 | void ledOn(); |
diana_s | 0:3cabc617d433 | 50 | /** This function turns led off. |
diana_s | 0:3cabc617d433 | 51 | */ |
diana_s | 0:3cabc617d433 | 52 | void ledOff(); |
diana_s | 0:3cabc617d433 | 53 | /** This function inverts the value of the led. |
diana_s | 0:3cabc617d433 | 54 | */ |
diana_s | 0:3cabc617d433 | 55 | void toggle(); |
diana_s | 1:55b5e6d28fb3 | 56 | |
diana_s | 1:55b5e6d28fb3 | 57 | /** This function makes the led blink on a specific duration. |
diana_s | 1:55b5e6d28fb3 | 58 | * |
diana_s | 1:55b5e6d28fb3 | 59 | * @param duration specifies how long the functions is going to wait during the blink. |
diana_s | 1:55b5e6d28fb3 | 60 | */ |
diana_s | 1:55b5e6d28fb3 | 61 | |
diana_s | 0:3cabc617d433 | 62 | void blink(float duration); |
diana_s | 0:3cabc617d433 | 63 | |
diana_s | 0:3cabc617d433 | 64 | private: |
diana_s | 0:3cabc617d433 | 65 | DigitalOut LEDpin; |
diana_s | 0:3cabc617d433 | 66 | }; |
diana_s | 0:3cabc617d433 | 67 | |
diana_s | 0:3cabc617d433 | 68 | #endif |
diana_s | 0:3cabc617d433 | 69 |