Matthew Shuman
/
Lab1TestAdvanced
This loops through PWM outputs connected to the red and green LED.
Diff: main.cpp
- Revision:
- 3:e13f77e8172a
- Parent:
- 2:758d7363957f
- Child:
- 4:a8b0243f29b7
--- a/main.cpp Thu Jun 09 20:22:00 2016 +0000 +++ b/main.cpp Fri Aug 12 22:03:48 2016 +0000 @@ -1,19 +1,39 @@ +/*! Lab1TestAdvanced + * Used for advanced LED blinking with the FRDM-KL46Z. + * \author Matthew Shuman + * + * \date August 12th, 2016 + + * \bug No bugs yet + + * @code + * #include "mbed.h" + * + * int main() + * { + * } + * @endcode + */ + #include "mbed.h" + +//This creates Pulse Width Modulated outputs, r and g, and connects them to the red and green LED. PwmOut r(LED_RED); PwmOut g(LED_GREEN); int main() { + //The period of the PWM is set to 1 millisecond. r.period(0.001f); g.period(0.001f); while (true) { for (float i = 0.0f; i < 1.0f ; i += 0.001f) { - float p = 2 * i; //Sweep the p value between 0 and 2, with .002 steps + float j = 2 * i; //Sweep the j value between 0 and 2, with .002 steps if(p<1) - r=p; + r=j; else - r=p-1; //Sweep the red LED 2 times during the loop, igorning the integer portion of the float number. + r=j-1; //Sweep the red LED 2 times during the loop, igorning the integer portion of the float number. g = i; //Sweep the green LED 1 time during the loop. wait (0.0025f); //Wait 2.5 milliseconds per iteration, 2.5 seconds per full loop. }