Simple test of two speed flashing LED toggled by button press with output to the serial monitor and monitoring time using the onboard RTC.

Dependencies:   mbed

nucleoBlink.cpp

Committer:
patthoyts
Date:
2014-03-04
Revision:
0:cde87f156401

File content as of revision 0:cde87f156401:

#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);
    }
}