This loops through PWM outputs connected to the red and green LED.
Dependencies: mbed
main.cpp@2:758d7363957f, 2016-06-09 (annotated)
- Committer:
- mattshuman
- Date:
- Thu Jun 09 20:22:00 2016 +0000
- Revision:
- 2:758d7363957f
- Parent:
- 1:eceee8965029
- Child:
- 3:e13f77e8172a
t;
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 | 0:62faec5d4c84 | 3 | PwmOut r(LED_RED); |
mattshuman | 0:62faec5d4c84 | 4 | PwmOut g(LED_GREEN); |
mattshuman | 0:62faec5d4c84 | 5 | |
mattshuman | 0:62faec5d4c84 | 6 | int main() |
mattshuman | 0:62faec5d4c84 | 7 | { |
mattshuman | 0:62faec5d4c84 | 8 | r.period(0.001f); |
mattshuman | 0:62faec5d4c84 | 9 | g.period(0.001f); |
mattshuman | 0:62faec5d4c84 | 10 | while (true) { |
mattshuman | 0:62faec5d4c84 | 11 | for (float i = 0.0f; i < 1.0f ; i += 0.001f) { |
mattshuman | 0:62faec5d4c84 | 12 | float p = 2 * i; //Sweep the p value between 0 and 2, with .002 steps |
mattshuman | 2:758d7363957f | 13 | if(p<1) |
mattshuman | 2:758d7363957f | 14 | r=p; |
mattshuman | 2:758d7363957f | 15 | else |
mattshuman | 2:758d7363957f | 16 | r=p-1; //Sweep the red LED 2 times during the loop, igorning the integer portion of the float number. |
mattshuman | 0:62faec5d4c84 | 17 | g = i; //Sweep the green LED 1 time during the loop. |
mattshuman | 0:62faec5d4c84 | 18 | wait (0.0025f); //Wait 2.5 milliseconds per iteration, 2.5 seconds per full loop. |
mattshuman | 0:62faec5d4c84 | 19 | } |
mattshuman | 0:62faec5d4c84 | 20 | } |
mattshuman | 0:62faec5d4c84 | 21 | } |