Basic example showing how to use the High Brightness LED present on the Discovery F334C8 board.

Dependencies:   HiBrightLED mbed

Committer:
bcostm
Date:
Wed Jun 17 06:33:41 2015 +0000
Revision:
0:adf2e8b61a3d
Initial version.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:adf2e8b61a3d 1 #include "mbed.h"
bcostm 0:adf2e8b61a3d 2 #include "HiBrightLED.h"
bcostm 0:adf2e8b61a3d 3
bcostm 0:adf2e8b61a3d 4 /*
bcostm 0:adf2e8b61a3d 5 Example showing how to use the High Brightness LED present
bcostm 0:adf2e8b61a3d 6 on the DISCO-F334C8 board.
bcostm 0:adf2e8b61a3d 7 */
bcostm 0:adf2e8b61a3d 8
bcostm 0:adf2e8b61a3d 9 DigitalOut red_led(LED1);
bcostm 0:adf2e8b61a3d 10
bcostm 0:adf2e8b61a3d 11 InterruptIn user_button(USER_BUTTON);
bcostm 0:adf2e8b61a3d 12
bcostm 0:adf2e8b61a3d 13 HiBrightLED hib_led;
bcostm 0:adf2e8b61a3d 14
bcostm 0:adf2e8b61a3d 15 uint32_t blink;
bcostm 0:adf2e8b61a3d 16
bcostm 0:adf2e8b61a3d 17 void button_pressed() {
bcostm 0:adf2e8b61a3d 18 static uint32_t state = 1;
bcostm 0:adf2e8b61a3d 19 blink = 0;
bcostm 0:adf2e8b61a3d 20 switch (state) {
bcostm 0:adf2e8b61a3d 21 case 0:
bcostm 0:adf2e8b61a3d 22 hib_led = 0.0; // OFF
bcostm 0:adf2e8b61a3d 23 break;
bcostm 0:adf2e8b61a3d 24 case 1:
bcostm 0:adf2e8b61a3d 25 hib_led = 0.05; // ON intermediate 1
bcostm 0:adf2e8b61a3d 26 break;
bcostm 0:adf2e8b61a3d 27 case 2:
bcostm 0:adf2e8b61a3d 28 hib_led = 0.2; // ON intermediate 2
bcostm 0:adf2e8b61a3d 29 break;
bcostm 0:adf2e8b61a3d 30 case 3:
bcostm 0:adf2e8b61a3d 31 hib_led = 1.0; // ON MAX
bcostm 0:adf2e8b61a3d 32 break;
bcostm 0:adf2e8b61a3d 33 case 4:
bcostm 0:adf2e8b61a3d 34 hib_led = 0.0; // ON / OFF
bcostm 0:adf2e8b61a3d 35 blink = 1;
bcostm 0:adf2e8b61a3d 36 default:
bcostm 0:adf2e8b61a3d 37 break;
bcostm 0:adf2e8b61a3d 38 }
bcostm 0:adf2e8b61a3d 39 state++;
bcostm 0:adf2e8b61a3d 40 if (state > 4) state = 0;
bcostm 0:adf2e8b61a3d 41 }
bcostm 0:adf2e8b61a3d 42
bcostm 0:adf2e8b61a3d 43 int main()
bcostm 0:adf2e8b61a3d 44 {
bcostm 0:adf2e8b61a3d 45 user_button.fall(&button_pressed);
bcostm 0:adf2e8b61a3d 46
bcostm 0:adf2e8b61a3d 47 while(1)
bcostm 0:adf2e8b61a3d 48 {
bcostm 0:adf2e8b61a3d 49 red_led = !red_led;
bcostm 0:adf2e8b61a3d 50 if (blink) {
bcostm 0:adf2e8b61a3d 51 hib_led = !hib_led;
bcostm 0:adf2e8b61a3d 52 }
bcostm 0:adf2e8b61a3d 53 wait(0.3);
bcostm 0:adf2e8b61a3d 54 }
bcostm 0:adf2e8b61a3d 55 }