Matthew Shuman
/
Lab1TestAdvanced
This loops through PWM outputs connected to the red and green LED.
main.cpp@0:62faec5d4c84, 2016-06-09 (annotated)
- Committer:
- mattshuman
- Date:
- Thu Jun 09 18:29:57 2016 +0000
- Revision:
- 0:62faec5d4c84
- Child:
- 1:eceee8965029
Initial version, which sweeps the brightness on the red and green LEDs at different rates.
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 | |
mattshuman | 0:62faec5d4c84 | 11 | while (true) { |
mattshuman | 0:62faec5d4c84 | 12 | for (float i = 0.0f; i < 1.0f ; i += 0.001f) { |
mattshuman | 0:62faec5d4c84 | 13 | float p = 2 * i; //Sweep the p value between 0 and 2, with .002 steps |
mattshuman | 0:62faec5d4c84 | 14 | r = p%1; //Sweep the red LED 2 times during the loop, igorning the integer portion of the float number. |
mattshuman | 0:62faec5d4c84 | 15 | g = i; //Sweep the green LED 1 time during the loop. |
mattshuman | 0:62faec5d4c84 | 16 | wait (0.0025f); //Wait 2.5 milliseconds per iteration, 2.5 seconds per full loop. |
mattshuman | 0:62faec5d4c84 | 17 | } |
mattshuman | 0:62faec5d4c84 | 18 | } |
mattshuman | 0:62faec5d4c84 | 19 | } |