Example PWM control of RGB LEDs
Dependencies: mbed
Fork of frdm_rgbled by
main.cpp
00001 #include "mbed.h" 00002 00003 PwmOut r(LED_RED); 00004 PwmOut g(LED_GREEN); 00005 00006 int main() 00007 { 00008 r.period(0.001f); 00009 g.period(0.001f); 00010 00011 while (true) { 00012 for (float i = 0.0f; i < 1.0f ; i += 0.001f) { 00013 float p = 3 * i; 00014 r = 1.0f - ((p < 1.0f) ? 1.0f - p : (p > 2.0f) ? p - 2.0f : 0.0f); 00015 g = 1.0f - ((p < 1.0f) ? p : (p > 2.0f) ? 0.0f : 2.0f - p); 00016 wait (0.0025f); 00017 } 00018 } 00019 }
Generated on Thu Jul 14 2022 17:01:37 by 1.7.2