Matthew Shuman
/
Lab1TestAdvanced3
Example showing comments.
Fork of Lab1TestAdvanced3 by
Blinker.h@0:fbca7accb93b, 2016-08-13 (annotated)
- Committer:
- mattshuman
- Date:
- Sat Aug 13 01:47:43 2016 +0000
- Revision:
- 0:fbca7accb93b
- Child:
- 1:94789e770417
Removed artifacts from source code.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mattshuman | 0:fbca7accb93b | 1 | /*! Lab1TestAdvanced3 |
mattshuman | 0:fbca7accb93b | 2 | * Used for advanced LED blinking with the FRDM-KL46Z. This adds a .h file to leverage modularity and also provides an example of a proper commenting style. |
mattshuman | 0:fbca7accb93b | 3 | * \author Matthew Shuman |
mattshuman | 0:fbca7accb93b | 4 | * |
mattshuman | 0:fbca7accb93b | 5 | * \date August 12th, 2016 |
mattshuman | 0:fbca7accb93b | 6 | |
mattshuman | 0:fbca7accb93b | 7 | * \bug No bugs yet |
mattshuman | 0:fbca7accb93b | 8 | |
mattshuman | 0:fbca7accb93b | 9 | * @code |
mattshuman | 0:fbca7accb93b | 10 | * #include "mbed.h" |
mattshuman | 0:fbca7accb93b | 11 | * |
mattshuman | 0:fbca7accb93b | 12 | * outputLED may be r or g, frequency is in Hertz, and brightness can range between 0 and 1. |
mattshuman | 0:fbca7accb93b | 13 | * void blink(output LED, frequency, brightness) |
mattshuman | 0:fbca7accb93b | 14 | * { |
mattshuman | 0:fbca7accb93b | 15 | * } |
mattshuman | 0:fbca7accb93b | 16 | * @endcode |
mattshuman | 0:fbca7accb93b | 17 | */ |
mattshuman | 0:fbca7accb93b | 18 | |
mattshuman | 0:fbca7accb93b | 19 | #include "mbed.h" |
mattshuman | 0:fbca7accb93b | 20 | // this class file is a template on using .h files. |
mattshuman | 0:fbca7accb93b | 21 | class Blinker |
mattshuman | 0:fbca7accb93b | 22 | { |
mattshuman | 0:fbca7accb93b | 23 | public: |
mattshuman | 0:fbca7accb93b | 24 | Blinker(void) { |
mattshuman | 0:fbca7accb93b | 25 | }; |
mattshuman | 0:fbca7accb93b | 26 | // class method to blink and LED based on the PwmOut class |
mattshuman | 0:fbca7accb93b | 27 | void blink(PwmOut outputLED, float frequency, float brightness) { |
mattshuman | 0:fbca7accb93b | 28 | outputLED.period(.001f); |
mattshuman | 0:fbca7accb93b | 29 | outputLED = 1- brightness; |
mattshuman | 0:fbca7accb93b | 30 | float duration = (1.0/frequency)/2; //dividing by 2 lets the microcontroller wait for half of the period before changing the LED. |
mattshuman | 0:fbca7accb93b | 31 | wait(duration); |
mattshuman | 0:fbca7accb93b | 32 | outputLED = 1.0; //LED is active low, so setting this to 1 turns off the LED. |
mattshuman | 0:fbca7accb93b | 33 | wait(duration); |
mattshuman | 0:fbca7accb93b | 34 | }; |
mattshuman | 0:fbca7accb93b | 35 | |
mattshuman | 0:fbca7accb93b | 36 | private: |
mattshuman | 0:fbca7accb93b | 37 | |
mattshuman | 0:fbca7accb93b | 38 | }; |