![](/media/cache/group/ST_logo_2020_blue_V_cmyk.jpg.50x50_q85.jpg)
Test application for the STMicroelectronics X-NUCLEO-LED61A1 LED Control Expansion Board showing several LED control modes.
Dependencies: X_NUCLEO_LED61A1 mbed
Fork of LedDimming_LED61A1 by
LED Control with the X-NUCLEO-LED61A1 Expansion Board
This application provides an example of usage of the X-NUCLEO-LED61A1 LED Control Expansion Board. It shows how to control a LED stripe load connected to the board through the following control modes:
- Manual PWM Dimming;
- Manual Analog Dimming;
- Sinusoidal PWM Dimming;
- Sinusoidal Analog Dimming;
- Photo-based Analog Dimming.
The button of the MCU board, when available, can be used in the following ways:
- Short Button Press [<0.5s] for Manual Dimming;
- Medium Button Press to Switch Demo;
- Long Button Press [>2s] to Switch Power ON/OFF.
The program starts in mode 1.
Revision 16:2497344ba436, committed 2017-07-13
- Comitter:
- Davidroid
- Date:
- Thu Jul 13 16:23:20 2017 +0000
- Parent:
- 15:ea1e402ce919
- Commit message:
- Adapting to ARM mbed coding style.
Changed in this revision
--- a/X_NUCLEO_LED61A1.lib Mon Mar 14 12:20:07 2016 +0000 +++ b/X_NUCLEO_LED61A1.lib Thu Jul 13 16:23:20 2017 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ST/code/X_NUCLEO_LED61A1/#5a7ee8e28f92 +https://developer.mbed.org/teams/ST/code/X_NUCLEO_LED61A1/#8cd869d64965
--- a/main.cpp Mon Mar 14 12:20:07 2016 +0000 +++ b/main.cpp Thu Jul 13 16:23:20 2017 +0000 @@ -43,7 +43,7 @@ #include "mbed.h" /* Component specific header files. */ -#include "led6001_class.h" +#include "Led6001.h" /* Definitions ---------------------------------------------------------------*/ @@ -104,7 +104,7 @@ DigitalOut button_pressed_led(LED1); /* LED Control Component. */ -LED6001 *led; +Led6001 *led; /* Interrupt flags. */ static volatile bool ticker_irq_triggered = false; @@ -134,7 +134,7 @@ * @param None. * @retval None. */ -void InitDemo(void) +void init_demo(void) { power_on = true; action = SWITCH_DEMO; @@ -146,40 +146,34 @@ * @param None. * @retval None. */ -void LEDHandler(void) +void led_handler(void) { static int tick = 0; static float pwm_dimming; static float analog_dimming; /* Handling the power switch. */ - if (action == SWITCH_POWER) - { + if (action == SWITCH_POWER) { /* Switching the LED power ON/OFF. */ power_on = !power_on; - if (power_on) - { + if (power_on) { /* Initializing PWM and Analog dimming to maximum values. */ pwm_dimming = 1.0f; analog_dimming = 1.0f; - } - else - { + } else { /* Printing to the console. */ printf("%-56s\r", "Power OFF"); /* Powering OFF the LED. */ - led->PowerOFF(); + led->power_off(); } } /* Handling the LED dimming when powered ON. */ - if (power_on) - { + if (power_on) { /* Switching to the next demo. */ - if (action == SWITCH_DEMO) - { + if (action == SWITCH_DEMO) { pwm_dimming = 1.0f; analog_dimming = 1.0f; tick = 0; @@ -187,12 +181,10 @@ } /* Setting the LED dimming depending on the selected demo. */ - switch (demo) - { + switch (demo) { /* Changing PWM dimming according to the user button. */ case MANUAL_PWM_DIMMING: - if (action == SWITCH_STATE) - { + if (action == SWITCH_STATE) { pwm_dimming -= DIMMING_STEP; pwm_dimming = (pwm_dimming < 0.0f ? 1.0f : pwm_dimming); } @@ -200,8 +192,7 @@ /* Changing Analog dimming according to the user button. */ case MANUAL_ANALOG_DIMMING: - if (action == SWITCH_STATE) - { + if (action == SWITCH_STATE) { analog_dimming -= DIMMING_STEP; analog_dimming = (analog_dimming < 0.0f ? 1.0f : analog_dimming); } @@ -223,20 +214,19 @@ /* Setting Analog dimming according to the photo sensor. */ case PHOTO_BASED_ANALOG_DIMMING: - analog_dimming = 1.0f - led->GetCurrent(); + analog_dimming = 1.0f - led->get_current(); action = SWITCH_STATE; break; } /* Writing PWM and Analog dimming values to the LED. */ - if (action != NO_ACTION) - { + if (action != NO_ACTION) { /* Printing to the console. */ printf("%d) %-26s --> Dimming: %0.2f\r", demo + 1, demos[demo], demo == MANUAL_PWM_DIMMING || demo == AUTOMATIC_PWM_DIMMING ? pwm_dimming : analog_dimming); /* Writing PWM and Analog dimming values to the LED. */ - led->SetPWMDimming(pwm_dimming); - led->SetAnalogDimming(analog_dimming); + led->set_pwm_dimming(pwm_dimming); + led->set_analog_dimming(analog_dimming); } } @@ -249,7 +239,7 @@ * @param None. * @retval None. */ -void TickerIRQ(void) +void ticker_irq(void) { ticker_irq_triggered = true; } @@ -259,7 +249,7 @@ * @param None. * @retval None. */ -void ButtonIRQ(void) +void button_irq(void) { button_irq_triggered = true; button.disable_irq(); @@ -270,10 +260,10 @@ * @param None. * @retval None. */ -void XFaultIRQ(void) +void xfault_irq(void) { xfault_irq_triggered = true; - led->DisableXFaultIRQ(); + led->disable_xfault_irq(); } /** @@ -281,31 +271,29 @@ * @param None. * @retval None. */ -void ButtonHandler(void) +void button_handler(void) { /* User Button's timer to measure the time the button remains pressed. */ static Timer button_pressed_timer; bool button_pressed_flag = (button.read() == 0 ? true : false); - if (button_pressed_flag) - { + if (button_pressed_flag) { button_pressed_led = 1; button_pressed_timer.start(); - } - else - { + } else { button_pressed_led = 0; button_pressed_timer.stop(); /* Either changing current demo's state or switching to the next demo. */ int time_pressed = button_pressed_timer.read_ms(); - if (time_pressed < SWITCH_DEMO_BUTTON_PRESS_ms) + if (time_pressed < SWITCH_DEMO_BUTTON_PRESS_ms) { action = SWITCH_STATE; - else if (time_pressed < SWITCH_POWER_BUTTON_PRESS_ms) + } else if (time_pressed < SWITCH_POWER_BUTTON_PRESS_ms) { action = SWITCH_DEMO; - else + } else { action = SWITCH_POWER; + } button_pressed_timer.reset(); } @@ -318,21 +306,21 @@ * @param None. * @retval None. */ -void XFaultHandler(void) +void xfault_handler(void) { /* Printing to the console. */ printf("XFAULT Interrupt detected! Re-initializing LED driver..."); /* Re-starting-up LED Control Component. */ - led->StartUp(); + led->start_up(); /* Printing to the console. */ printf("Done.\r\n\n"); /* Re-initializing the demo. */ - InitDemo(); + init_demo(); - led->EnableXFaultIRQ(); + led->enable_xfault_irq(); } @@ -346,8 +334,9 @@ printf("LED Control Application Example\r\n\n" \ "Demos:\r\n"); int demo = 0; - for (demo = 0; demo < LED_DEMO_SIZE; demo++) + for (demo = 0; demo < LED_DEMO_SIZE; demo++) { printf("%d) %-26s\r\n", demo + 1, demos[demo]); + } printf("\r\nActions:\r\n" \ "+ Short Button Press [<%.1fs] --> Manual Dimming\r\n" \ "+ Medium Button Press --> Switch Demo\r\n" \ @@ -355,41 +344,38 @@ , SWITCH_DEMO_BUTTON_PRESS_ms / 1000.0f, SWITCH_POWER_BUTTON_PRESS_ms / 1000.0f); /* Initializing LED Control Component. */ - led = new LED6001(D4, A3, D6, D5); - if (led->Init() != COMPONENT_OK) + led = new Led6001(D4, A3, D6, D5); + if (led->init() != COMPONENT_OK) { exit(EXIT_FAILURE); + } /* Attaching interrupt request functions. */ - button.fall(ButtonIRQ); - button.rise(ButtonIRQ); - led->AttachXFaultIRQ(&XFaultIRQ); - led->EnableXFaultIRQ(); - ticker.attach_us(TickerIRQ, LOOP_PERIOD_us); + button.fall(button_irq); + button.rise(button_irq); + led->attach_xfault_irq(&xfault_irq); + led->enable_xfault_irq(); + ticker.attach_us(ticker_irq, LOOP_PERIOD_us); /* Starting-up LED Control Component. */ - led->StartUp(); + led->start_up(); /* Initializing the demo. */ - InitDemo(); + init_demo(); /*----- LED Control. -----*/ /* Either performing the component handler, interrupt handlers, or waiting for events. */ - while (true) - { - if (ticker_irq_triggered) - { + while (true) { + if (ticker_irq_triggered) { ticker_irq_triggered = false; - LEDHandler(); - } else if (button_irq_triggered) - { + led_handler(); + } else if (button_irq_triggered) { button_irq_triggered = false; - ButtonHandler(); - } else if (xfault_irq_triggered) - { + button_handler(); + } else if (xfault_irq_triggered) { xfault_irq_triggered = false; - XFaultHandler(); + xfault_handler(); } else { /* It is recommended that SEVONPEND in the System Control Register is NOT set. */ __WFE();
--- a/mbed.bld Mon Mar 14 12:20:07 2016 +0000 +++ b/mbed.bld Thu Jul 13 16:23:20 2017 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/165afa46840b \ No newline at end of file +https://mbed.org/users/mbed_official/code/mbed/builds/22da6e220af6 \ No newline at end of file