changing RGB color with the ticker function

Dependencies:   mbed-src

Fork of RGB_WIZwiki-W7500 by FOURNET Olivier

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 /* W7500
00004 LED1 = LED_RED   = LEDR = PC_8
00005 LED2 = LED_GREEN = LEDG = PC_9
00006 LED3 = LED_BLUE  = LEDB = PC_5
00007 LED4 = LED_BLUE
00008 */
00009 
00010 DigitalOut red(LED_RED);
00011 DigitalOut green(LED_GREEN);
00012 DigitalOut blue(LED_BLUE);
00013 
00014 Ticker toggle_led_ticker;
00015 
00016 int i = 1;
00017 
00018 void toggle_led() 
00019 {
00020     red = i & 1;
00021     blue = i & 2;
00022     green = i & 4;
00023     ++i;
00024     if(i == 7) i = 1;
00025 }
00026 
00027 int main() 
00028 {
00029     // Init the ticker with the address of the function (toggle_led) to be attached and the interval (100 ms)
00030     toggle_led_ticker.attach(&toggle_led, 0.5);
00031     
00032     while(true) 
00033     { 
00034      // Do other things...  
00035     }
00036 }