Example PWM control of RGB LEDs

Dependencies:   mbed

Fork of frdm_rgbled by Freescale

Using three PWM channels to mix the onboard RGB (Red, Green, Blue) LED to make a variety of colors.

NOTE: This example code does not work with FRDM-K64F.

Committer:
sam_grove
Date:
Wed Jul 16 10:20:45 2014 +0000
Revision:
7:ad8295723268
Parent:
5:14891bb08b35
update formatting and mbed library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris 0:cf8a48b1fb23 1 #include "mbed.h"
chris 0:cf8a48b1fb23 2
Kojto 5:14891bb08b35 3 PwmOut r(LED_RED);
Kojto 5:14891bb08b35 4 PwmOut g(LED_GREEN);
chris 0:cf8a48b1fb23 5
sam_grove 7:ad8295723268 6 int main()
sam_grove 7:ad8295723268 7 {
sam_grove 7:ad8295723268 8 r.period(0.001f);
sam_grove 7:ad8295723268 9 g.period(0.001f);
chris 1:eabc6f5b51d6 10
emilmont 2:03e5c29343d1 11 while (true) {
sam_grove 7:ad8295723268 12 for (float i = 0.0f; i < 1.0f ; i += 0.001f) {
chris 1:eabc6f5b51d6 13 float p = 3 * i;
sam_grove 7:ad8295723268 14 r = 1.0f - ((p < 1.0f) ? 1.0f - p : (p > 2.0f) ? p - 2.0f : 0.0f);
sam_grove 7:ad8295723268 15 g = 1.0f - ((p < 1.0f) ? p : (p > 2.0f) ? 0.0f : 2.0f - p);
sam_grove 7:ad8295723268 16 wait (0.0025f);
chris 1:eabc6f5b51d6 17 }
chris 1:eabc6f5b51d6 18 }
sam_grove 7:ad8295723268 19 }