Freescale / Mbed 2 deprecated frdm_Grove_RGB_LED_Example

Dependencies:   Chainable_RGB_LED mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "ChainableLED.h"
00003 
00004 #define NUM_LED 3
00005 
00006 // ChainableLED(clk, data, number_of_leds)
00007 ChainableLED color_led(D2, D3, NUM_LED);
00008 
00009 int main()
00010 {
00011     uint8_t index = 0;
00012     while(1) {
00013         // generate random RGB values for LED's
00014         uint8_t R = rand();
00015         uint8_t G = rand();
00016         uint8_t B = rand();
00017         // print message to terminal
00018         printf("index = %d, R=%x,G=%x,B=%x,",index,R,G,B);
00019 
00020         // ChainableLED.setColorRGB(index_of_led, red, green, blue)
00021         color_led.setColorRGB(index++, R, G, B);    // increase brightness cascade down chain of LED's
00022         index = ((index+1) % NUM_LED);              // cycle through LED's
00023         wait(0.05);
00024     }
00025 }
00026