Simple test of two speed flashing LED toggled by button press with output to the serial monitor and monitoring time using the onboard RTC.
Diff: nucleoBlink.cpp
- Revision:
- 0:cde87f156401
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nucleoBlink.cpp Tue Mar 04 13:18:29 2014 +0000 @@ -0,0 +1,44 @@ +#include "mbed.h" + +DigitalOut led(LED1); +InterruptIn btn(USER_BUTTON); +Serial serial(SERIAL_TX, SERIAL_RX); + +enum {DELAY_SLOW = 500000, DELAY_FAST = 100000, DELAY_FLASH=50000 }; +long delay = DELAY_FAST; +bool pressed = false; +long counter = 0; + +static void flash() +{ + for (int n = 0; n < 12; ++n) { + led = !led; + wait_us(DELAY_FLASH); + } +} +static void onButtonPress() +{ + delay = (delay == DELAY_SLOW) ? DELAY_FAST : DELAY_SLOW; + pressed = true; +} +int +main() +{ + serial.baud(115200); + btn.fall(&onButtonPress); + flash(); + set_time(1393936792); // set the onboard RTC + printf("MBED Nucleo Blink Test (v1.0)\n"); + while (true) + { + led = !led; + ++counter; + if ((counter % 10) == 0) { + time_t seconds = time(NULL); + printf("%d %d %s", counter, seconds, ctime(&seconds)); + } + if (pressed) { pressed = false; printf("# button pressed\n"); } + wait_us(delay); + } +} + \ No newline at end of file