This loops through PWM outputs connected to the red and green LED.
Dependencies: mbed
main.cpp@1:eceee8965029, 2016-06-09 (annotated)
- Committer:
- mattshuman
- Date:
- Thu Jun 09 19:48:22 2016 +0000
- Revision:
- 1:eceee8965029
- Parent:
- 0:62faec5d4c84
- Child:
- 2:758d7363957f
Tried inserting header comments.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mattshuman | 1:eceee8965029 | 1 | /** My HelloWorld class. |
mattshuman | 1:eceee8965029 | 2 | * Used for printing "Hello World" on USB serial. |
mattshuman | 1:eceee8965029 | 3 | * |
mattshuman | 1:eceee8965029 | 4 | * Example: |
mattshuman | 1:eceee8965029 | 5 | * @code |
mattshuman | 1:eceee8965029 | 6 | * #include "mbed.h" |
mattshuman | 1:eceee8965029 | 7 | * #include "HelloWorld.h" |
mattshuman | 1:eceee8965029 | 8 | * |
mattshuman | 1:eceee8965029 | 9 | * HelloWorld hw(); |
mattshuman | 1:eceee8965029 | 10 | * |
mattshuman | 1:eceee8965029 | 11 | * int main() { |
mattshuman | 1:eceee8965029 | 12 | * hw.printIt(2); |
mattshuman | 1:eceee8965029 | 13 | * } |
mattshuman | 1:eceee8965029 | 14 | * @endcode |
mattshuman | 1:eceee8965029 | 15 | */ |
mattshuman | 1:eceee8965029 | 16 | |
mattshuman | 0:62faec5d4c84 | 17 | #include "mbed.h" |
mattshuman | 0:62faec5d4c84 | 18 | |
mattshuman | 1:eceee8965029 | 19 | |
mattshuman | 1:eceee8965029 | 20 | |
mattshuman | 0:62faec5d4c84 | 21 | PwmOut r(LED_RED); |
mattshuman | 0:62faec5d4c84 | 22 | PwmOut g(LED_GREEN); |
mattshuman | 0:62faec5d4c84 | 23 | |
mattshuman | 0:62faec5d4c84 | 24 | int main() |
mattshuman | 0:62faec5d4c84 | 25 | { |
mattshuman | 0:62faec5d4c84 | 26 | r.period(0.001f); |
mattshuman | 0:62faec5d4c84 | 27 | g.period(0.001f); |
mattshuman | 0:62faec5d4c84 | 28 | |
mattshuman | 0:62faec5d4c84 | 29 | while (true) { |
mattshuman | 0:62faec5d4c84 | 30 | for (float i = 0.0f; i < 1.0f ; i += 0.001f) { |
mattshuman | 0:62faec5d4c84 | 31 | float p = 2 * i; //Sweep the p value between 0 and 2, with .002 steps |
mattshuman | 0:62faec5d4c84 | 32 | r = p%1; //Sweep the red LED 2 times during the loop, igorning the integer portion of the float number. |
mattshuman | 0:62faec5d4c84 | 33 | g = i; //Sweep the green LED 1 time during the loop. |
mattshuman | 0:62faec5d4c84 | 34 | wait (0.0025f); //Wait 2.5 milliseconds per iteration, 2.5 seconds per full loop. |
mattshuman | 0:62faec5d4c84 | 35 | } |
mattshuman | 0:62faec5d4c84 | 36 | } |
mattshuman | 0:62faec5d4c84 | 37 | } |