Example program for the Seeed Studio Grove RGB Chainable LED's.
Dependencies: Chainable_RGB_LED mbed
Fork of be_colorful by
main.cpp@3:9e2ef62d62b4, 2015-05-03 (annotated)
- Committer:
- sam_grove
- Date:
- Sun May 03 02:04:01 2015 +0000
- Revision:
- 3:9e2ef62d62b4
- Parent:
- 2:4dae2f80828e
Update libraries.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yihui | 0:71564ae5e242 | 1 | #include "mbed.h" |
yihui | 0:71564ae5e242 | 2 | #include "ChainableLED.h" |
yihui | 0:71564ae5e242 | 3 | |
mbedAustin | 2:4dae2f80828e | 4 | #define NUM_LED 3 |
yihui | 1:10700868060f | 5 | |
yihui | 0:71564ae5e242 | 6 | // ChainableLED(clk, data, number_of_leds) |
mbedAustin | 2:4dae2f80828e | 7 | ChainableLED color_led(D6, D7, NUM_LED); |
yihui | 1:10700868060f | 8 | |
mbedAustin | 2:4dae2f80828e | 9 | int main() |
yihui | 1:10700868060f | 10 | { |
mbedAustin | 2:4dae2f80828e | 11 | uint8_t index = 0; |
mbedAustin | 2:4dae2f80828e | 12 | while(1) { |
mbedAustin | 2:4dae2f80828e | 13 | // generate random RGB values for LED's |
mbedAustin | 2:4dae2f80828e | 14 | uint8_t R = rand(); |
mbedAustin | 2:4dae2f80828e | 15 | uint8_t G = rand(); |
mbedAustin | 2:4dae2f80828e | 16 | uint8_t B = rand(); |
mbedAustin | 2:4dae2f80828e | 17 | // print message to terminal |
mbedAustin | 2:4dae2f80828e | 18 | printf("index = %d, R=%x,G=%x,B=%x,",index,R,G,B); |
yihui | 0:71564ae5e242 | 19 | |
yihui | 0:71564ae5e242 | 20 | // ChainableLED.setColorRGB(index_of_led, red, green, blue) |
mbedAustin | 2:4dae2f80828e | 21 | color_led.setColorRGB(index++, R, G, B); // increase brightness cascade down chain of LED's |
mbedAustin | 2:4dae2f80828e | 22 | index = ((index+1) % NUM_LED); // cycle through LED's |
yihui | 1:10700868060f | 23 | wait(0.05); |
yihui | 0:71564ae5e242 | 24 | } |
yihui | 0:71564ae5e242 | 25 | } |
yihui | 0:71564ae5e242 | 26 |