changing RGB color with the ticker function

Dependencies:   mbed-src

Fork of RGB_WIZwiki-W7500 by FOURNET Olivier

Committer:
Fo170
Date:
Mon May 09 21:17:31 2016 +0000
Revision:
4:fdb8fe5b6a74
Parent:
3:c97f8e12e04c
essai changing RGB with the ticker function

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:50d2b9c62765 1 #include "mbed.h"
mbedAustin 1:5160ea45399b 2
Fo170 3:c97f8e12e04c 3 /* W7500
Fo170 3:c97f8e12e04c 4 LED1 = LED_RED = LEDR = PC_8
Fo170 3:c97f8e12e04c 5 LED2 = LED_GREEN = LEDG = PC_9
Fo170 3:c97f8e12e04c 6 LED3 = LED_BLUE = LEDB = PC_5
Fo170 3:c97f8e12e04c 7 LED4 = LED_BLUE
Fo170 3:c97f8e12e04c 8 */
Fo170 3:c97f8e12e04c 9
Fo170 3:c97f8e12e04c 10 DigitalOut red(LED_RED);
Fo170 3:c97f8e12e04c 11 DigitalOut green(LED_GREEN);
Fo170 3:c97f8e12e04c 12 DigitalOut blue(LED_BLUE);
Fo170 3:c97f8e12e04c 13
Fo170 4:fdb8fe5b6a74 14 Ticker toggle_led_ticker;
Fo170 4:fdb8fe5b6a74 15
Fo170 4:fdb8fe5b6a74 16 int i = 1;
mbedAustin 1:5160ea45399b 17
Fo170 4:fdb8fe5b6a74 18 void toggle_led()
Fo170 4:fdb8fe5b6a74 19 {
Fo170 4:fdb8fe5b6a74 20 red = i & 1;
Fo170 4:fdb8fe5b6a74 21 blue = i & 2;
Fo170 4:fdb8fe5b6a74 22 green = i & 4;
Fo170 4:fdb8fe5b6a74 23 ++i;
Fo170 4:fdb8fe5b6a74 24 if(i == 7) i = 1;
Fo170 4:fdb8fe5b6a74 25 }
Fo170 4:fdb8fe5b6a74 26
Fo170 4:fdb8fe5b6a74 27 int main()
Fo170 4:fdb8fe5b6a74 28 {
Fo170 4:fdb8fe5b6a74 29 // Init the ticker with the address of the function (toggle_led) to be attached and the interval (100 ms)
Fo170 4:fdb8fe5b6a74 30 toggle_led_ticker.attach(&toggle_led, 0.5);
Fo170 4:fdb8fe5b6a74 31
Fo170 4:fdb8fe5b6a74 32 while(true)
Fo170 4:fdb8fe5b6a74 33 {
Fo170 4:fdb8fe5b6a74 34 // Do other things...
Fo170 3:c97f8e12e04c 35 }
mbed_official 0:50d2b9c62765 36 }