Matthew Shuman
/
Lab1TestAdvanced
This loops through PWM outputs connected to the red and green LED.
Diff: main.cpp
- Revision:
- 2:758d7363957f
- Parent:
- 1:eceee8965029
- Child:
- 3:e13f77e8172a
diff -r eceee8965029 -r 758d7363957f main.cpp --- a/main.cpp Thu Jun 09 19:48:22 2016 +0000 +++ b/main.cpp Thu Jun 09 20:22:00 2016 +0000 @@ -1,23 +1,5 @@ -/** My HelloWorld class. - * Used for printing "Hello World" on USB serial. - * - * Example: - * @code - * #include "mbed.h" - * #include "HelloWorld.h" - * - * HelloWorld hw(); - * - * int main() { - * hw.printIt(2); - * } - * @endcode - */ - #include "mbed.h" - - PwmOut r(LED_RED); PwmOut g(LED_GREEN); @@ -25,11 +7,13 @@ { 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 - r = p%1; //Sweep the red LED 2 times during the loop, igorning the integer portion of the float number. + if(p<1) + r=p; + else + r=p-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. }