Simple firmware to test the I/O capabilities of a Nucleo 64 board

Dependencies:   mbed

Revision:
0:43a77ff47221
Child:
1:69c43e344369
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Mar 14 02:30:27 2016 +0000
@@ -0,0 +1,53 @@
+#include "mbed.h"
+
+#define DEBUG_0_PRINT_OUT_ENABLE  1
+#if DEBUG_0_PRINT_OUT_ENABLE
+#define DEBUG_0(...) { printf(__VA_ARGS__); }
+#else
+#define DEBUG_0(...) /* nothing */
+#endif /* #if DEBUG_0_PRINT_OUT_ENABLE */
+
+#define LED_ON                      1           // LED is ACTIVE HIGH. It turns ON when the control pin is HIGH
+#define LED_OFF                     0           // LED is ACTIVE HIGH. It turns OFF when the control pin is LOW
+#define BUTTON_PRESSED_LED_STATE    LED_ON
+#define BUTTON_RELEASED_LED_STATE   LED_OFF
+
+DigitalOut      led1(LED1);
+InterruptIn     userButton(USER_BUTTON);
+
+void 
+buttonPressedCallback(void)
+{
+    led1 = BUTTON_PRESSED_LED_STATE;
+    DEBUG_0("button pressed\n");
+}
+
+void
+buttonReleasedCallback(void)
+{
+    led1 = BUTTON_RELEASED_LED_STATE;
+    DEBUG_0("button released\n");
+}
+
+void
+initBoard(void)
+{
+    // Init LED to turn ON by default
+    led1 = BUTTON_RELEASED_LED_STATE;
+    // Init button pressed and released behavior
+    userButton.rise(buttonReleasedCallback);    // Button is ACTIVE LOW. Released the button pull input pin HIGH, triggering the Rising Edge interrupt.
+    userButton.fall(buttonPressedCallback);     // Button is ACTIVE LOW. Pressed the button pull input pin LOW, triggering the Falling Edge interrupt.
+    userButton.enable_irq();
+}
+
+int 
+main() 
+{
+    initBoard();
+    led1 = LED_ON;
+    wait_ms(1000);
+    led1 = LED_OFF;
+    wait_ms(1000);
+    while(1) {
+    }
+}