changing RGB color with the ticker function
Fork of RGB_WIZwiki-W7500 by
Revision 4:fdb8fe5b6a74, committed 2016-05-09
- Comitter:
- Fo170
- Date:
- Mon May 09 21:17:31 2016 +0000
- Parent:
- 3:c97f8e12e04c
- Commit message:
- essai changing RGB with the ticker function
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r c97f8e12e04c -r fdb8fe5b6a74 main.cpp --- a/main.cpp Mon May 09 20:31:16 2016 +0000 +++ b/main.cpp Mon May 09 21:17:31 2016 +0000 @@ -11,15 +11,26 @@ DigitalOut green(LED_GREEN); DigitalOut blue(LED_BLUE); -int i; +Ticker toggle_led_ticker; + +int i = 1; -int main() { - while(1) { - for (i=1; i<7; i++) { - red = i & 1; - blue = i & 2; - green = i & 4; - wait(0.2); - } +void toggle_led() +{ + red = i & 1; + blue = i & 2; + green = i & 4; + ++i; + if(i == 7) i = 1; +} + +int main() +{ + // Init the ticker with the address of the function (toggle_led) to be attached and the interval (100 ms) + toggle_led_ticker.attach(&toggle_led, 0.5); + + while(true) + { + // Do other things... } } \ No newline at end of file