This FRDM-KL25Z demo will blink the RGB LED with all colors. The touch slider input controls the blinking frequency. The UART output shows the touch slider input.

Dependencies:   TSI mbed

main.cpp

Committer:
jewirth
Date:
2014-05-30
Revision:
0:6f33cc0cd2ac
Child:
1:609d9df3ffdc

File content as of revision 0:6f33cc0cd2ac:

#include "mbed.h"

#define LED_ON                  0
#define LED_OFF                 1
#define RGB_COMPONENTS          3
#define RGB_COLORS              ((int) pow(2 *1.0, RGB_COMPONENTS *1.0))
#define DELAY                   0.5

DigitalOut led_rgb_red(LED1);   // red
DigitalOut led_rgb_grn(LED2);   // green
DigitalOut led_rgb_blu(LED3);   // blue

DigitalOut led_rgb[RGB_COMPONENTS] = {led_rgb_red, led_rgb_grn, led_rgb_blu};

int main()
{
    // turn all LEDs off
    for (int i=0; i<RGB_COMPONENTS; i++)
        led_rgb[i] = LED_OFF;
    
    while(1)
    {
        // show all colors
        for (int i=0; i<RGB_COLORS; i++, wait(DELAY))   // for each possible color
            for (int j=0; j<RGB_COMPONENTS; j++)            // for each LED component
                led_rgb[j] = ( i & 1<<j ) ? LED_ON : LED_OFF;   // set LED component according to active color
    }
}