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.
Diff: main.cpp
- Revision:
- 14:f2ba2ca417d3
- Parent:
- 7:5763474c7551
- Child:
- 15:ea1e402ce919
diff -r f6474661f0cb -r f2ba2ca417d3 main.cpp
--- a/main.cpp Fri Mar 11 15:54:52 2016 +0000
+++ b/main.cpp Mon Mar 14 10:07:04 2016 +0000
@@ -50,25 +50,22 @@
/* PI. */
#ifndef M_PI
- #define M_PI (3.14159265358979323846f)
+ #define M_PI (3.14159265358979323846f)
#endif
/* Loop period in micro-seconds. */
-#define LOOP_PERIOD_us (1E5)
+#define LOOP_PERIOD_us (1E5)
/* Sin period in micro-seconds. */
-#define PWM_SIN_PERIOD_us (1E7)
-#define ANALOG_SIN_PERIOD_us (1E7)
+#define PWM_SIN_PERIOD_us (1E7)
+#define ANALOG_SIN_PERIOD_us (1E7)
/* Duration of button press in milli-seconds. */
-#define SWITCH_DEMO_BUTTON_PRESS_ms (500)
-#define SWITCH_POWER_BUTTON_PRESS_ms (2000)
-
-/* Duration of initialization interval in milli-seconds. */
-#define INITIALIZATION_INTERVAL_ms (2000)
+#define SWITCH_DEMO_BUTTON_PRESS_ms (500)
+#define SWITCH_POWER_BUTTON_PRESS_ms (2000)
/* Dimming Step. */
-#define DIMMING_STEP (0.05f)
+#define DIMMING_STEP (0.05f)
/* Types ---------------------------------------------------------------------*/
@@ -110,19 +107,15 @@
LED6001 *led;
/* Interrupt flags. */
-static volatile bool ticker_irq_triggered;
-static volatile bool button_irq_triggered;
-static volatile bool xfault_irq_triggered;
+static volatile bool ticker_irq_triggered = false;
+static volatile bool button_irq_triggered = false;
+static volatile bool xfault_irq_triggered = false;
/* Demo State. */
static volatile LED_Demo_t demo;
static volatile LED_Action_t action;
static volatile bool power_on;
-/* PWM and Analog dimming values. */
-static float pwm_dimming;
-static float analog_dimming;
-
/* Demos' Names. */
static char* demos[] =
{
@@ -137,36 +130,15 @@
/* Functions -----------------------------------------------------------------*/
/**
- * @brief Initilizing the demo.
+ * @brief Initializing the demo.
* @param None.
* @retval None.
*/
-void LEDInit(void)
+void InitDemo(void)
{
- /* Printing to the console. */
- printf("Initializing LED driver...");
-
- /* Initializing Interrupt flags. */
- button_irq_triggered = false;
- xfault_irq_triggered = false;
- ticker_irq_triggered = false;
-
- /* Initializing Demo. */
power_on = true;
action = SWITCH_DEMO;
demo = (LED_Demo_t) (LED_DEMO_SIZE - 1);
-
- /* Initializing PWM and Analog dimming to maximum values. */
- pwm_dimming = 1.0f;
- analog_dimming = 1.0f;
-
- /* Start-up sequence. */
- led->PowerOFF();
- wait_ms(INITIALIZATION_INTERVAL_ms);
- led->PowerON();
-
- /* Printing to the console. */
- printf("Done.\r\n\nDemo:\r\n");
}
/**
@@ -177,6 +149,8 @@
void LEDHandler(void)
{
static int tick = 0;
+ static float pwm_dimming;
+ static float analog_dimming;
/* Handling the power switch. */
if (action == SWITCH_POWER)
@@ -347,10 +321,16 @@
void XFaultHandler(void)
{
/* Printing to the console. */
- printf("XFAULT Interrupt detected! Re-initializing LED driver...\r\n");
+ printf("XFAULT Interrupt detected! Re-initializing LED driver...");
+
+ /* Re-starting-up LED Control Component. */
+ led->StartUp();
+
+ /* Printing to the console. */
+ printf("Done.\r\n\n");
/* Re-initializing the demo. */
- LEDInit();
+ InitDemo();
led->EnableXFaultIRQ();
}
@@ -375,7 +355,7 @@
, 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);
+ led = new LED6001(D4, A3, D7, D5);
if (led->Init() != COMPONENT_OK)
exit(EXIT_FAILURE);
@@ -386,8 +366,11 @@
led->EnableXFaultIRQ();
ticker.attach_us(TickerIRQ, LOOP_PERIOD_us);
+ /* Starting-up LED Control Component. */
+ led->StartUp();
+
/* Initializing the demo. */
- LEDInit();
+ InitDemo();
/*----- LED Control. -----*/
