Matthew Shuman
/
Lab1TestAdvanced
This loops through PWM outputs connected to the red and green LED.
main.cpp@4:a8b0243f29b7, 2016-08-13 (annotated)
- Committer:
- mattshuman
- Date:
- Sat Aug 13 08:36:34 2016 +0000
- Revision:
- 4:a8b0243f29b7
- Parent:
- 3:e13f77e8172a
- Child:
- 5:10267572c71b
Updated the documentation.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mattshuman | 0:62faec5d4c84 | 1 | #include "mbed.h" |
mattshuman | 0:62faec5d4c84 | 2 | |
mattshuman | 3:e13f77e8172a | 3 | //This creates Pulse Width Modulated outputs, r and g, and connects them to the red and green LED. |
mattshuman | 0:62faec5d4c84 | 4 | PwmOut r(LED_RED); |
mattshuman | 0:62faec5d4c84 | 5 | PwmOut g(LED_GREEN); |
mattshuman | 0:62faec5d4c84 | 6 | |
mattshuman | 0:62faec5d4c84 | 7 | int main() |
mattshuman | 0:62faec5d4c84 | 8 | { |
mattshuman | 3:e13f77e8172a | 9 | //The period of the PWM is set to 1 millisecond. |
mattshuman | 0:62faec5d4c84 | 10 | r.period(0.001f); |
mattshuman | 0:62faec5d4c84 | 11 | g.period(0.001f); |
mattshuman | 0:62faec5d4c84 | 12 | while (true) { |
mattshuman | 0:62faec5d4c84 | 13 | for (float i = 0.0f; i < 1.0f ; i += 0.001f) { |
mattshuman | 3:e13f77e8172a | 14 | float j = 2 * i; //Sweep the j value between 0 and 2, with .002 steps |
mattshuman | 2:758d7363957f | 15 | if(p<1) |
mattshuman | 3:e13f77e8172a | 16 | r=j; |
mattshuman | 2:758d7363957f | 17 | else |
mattshuman | 3:e13f77e8172a | 18 | r=j-1; //Sweep the red LED 2 times during the loop, igorning the integer portion of the float number. |
mattshuman | 0:62faec5d4c84 | 19 | g = i; //Sweep the green LED 1 time during the loop. |
mattshuman | 0:62faec5d4c84 | 20 | wait (0.0025f); //Wait 2.5 milliseconds per iteration, 2.5 seconds per full loop. |
mattshuman | 0:62faec5d4c84 | 21 | } |
mattshuman | 0:62faec5d4c84 | 22 | } |
mattshuman | 0:62faec5d4c84 | 23 | } |