This loops through PWM outputs connected to the red and green LED.
Dependencies: mbed
main.cpp@3:e13f77e8172a, 2016-08-12 (annotated)
- Committer:
- mattshuman
- Date:
- Fri Aug 12 22:03:48 2016 +0000
- Revision:
- 3:e13f77e8172a
- Parent:
- 2:758d7363957f
- Child:
- 4:a8b0243f29b7
Second test program, showing some types of comments used to explain a non-trivial program.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mattshuman | 3:e13f77e8172a | 1 | /*! Lab1TestAdvanced |
mattshuman | 3:e13f77e8172a | 2 | * Used for advanced LED blinking with the FRDM-KL46Z. |
mattshuman | 3:e13f77e8172a | 3 | * \author Matthew Shuman |
mattshuman | 3:e13f77e8172a | 4 | * |
mattshuman | 3:e13f77e8172a | 5 | * \date August 12th, 2016 |
mattshuman | 3:e13f77e8172a | 6 | |
mattshuman | 3:e13f77e8172a | 7 | * \bug No bugs yet |
mattshuman | 3:e13f77e8172a | 8 | |
mattshuman | 3:e13f77e8172a | 9 | * @code |
mattshuman | 3:e13f77e8172a | 10 | * #include "mbed.h" |
mattshuman | 3:e13f77e8172a | 11 | * |
mattshuman | 3:e13f77e8172a | 12 | * int main() |
mattshuman | 3:e13f77e8172a | 13 | * { |
mattshuman | 3:e13f77e8172a | 14 | * } |
mattshuman | 3:e13f77e8172a | 15 | * @endcode |
mattshuman | 3:e13f77e8172a | 16 | */ |
mattshuman | 3:e13f77e8172a | 17 | |
mattshuman | 0:62faec5d4c84 | 18 | #include "mbed.h" |
mattshuman | 0:62faec5d4c84 | 19 | |
mattshuman | 3:e13f77e8172a | 20 | |
mattshuman | 3:e13f77e8172a | 21 | //This creates Pulse Width Modulated outputs, r and g, and connects them to the red and green LED. |
mattshuman | 0:62faec5d4c84 | 22 | PwmOut r(LED_RED); |
mattshuman | 0:62faec5d4c84 | 23 | PwmOut g(LED_GREEN); |
mattshuman | 0:62faec5d4c84 | 24 | |
mattshuman | 0:62faec5d4c84 | 25 | int main() |
mattshuman | 0:62faec5d4c84 | 26 | { |
mattshuman | 3:e13f77e8172a | 27 | //The period of the PWM is set to 1 millisecond. |
mattshuman | 0:62faec5d4c84 | 28 | r.period(0.001f); |
mattshuman | 0:62faec5d4c84 | 29 | g.period(0.001f); |
mattshuman | 0:62faec5d4c84 | 30 | while (true) { |
mattshuman | 0:62faec5d4c84 | 31 | for (float i = 0.0f; i < 1.0f ; i += 0.001f) { |
mattshuman | 3:e13f77e8172a | 32 | float j = 2 * i; //Sweep the j value between 0 and 2, with .002 steps |
mattshuman | 2:758d7363957f | 33 | if(p<1) |
mattshuman | 3:e13f77e8172a | 34 | r=j; |
mattshuman | 2:758d7363957f | 35 | else |
mattshuman | 3:e13f77e8172a | 36 | r=j-1; //Sweep the red LED 2 times during the loop, igorning the integer portion of the float number. |
mattshuman | 0:62faec5d4c84 | 37 | g = i; //Sweep the green LED 1 time during the loop. |
mattshuman | 0:62faec5d4c84 | 38 | wait (0.0025f); //Wait 2.5 milliseconds per iteration, 2.5 seconds per full loop. |
mattshuman | 0:62faec5d4c84 | 39 | } |
mattshuman | 0:62faec5d4c84 | 40 | } |
mattshuman | 0:62faec5d4c84 | 41 | } |