Blinky LED for STM32F401 - replacement candidate for application shipped with board - uses <Timer.h> to seed pseudo-random number generator so that the blink sequence varies between incarnations.

Dependencies:   mbed

main.cpp

Committer:
nucleo
Date:
2014-05-20
Revision:
0:42458802c36f

File content as of revision 0:42458802c36f:

#include "mbed.h"
#include "stdlib.h"
#include <Timer.h>

InterruptIn mybutton(PC_13); // B1

DigitalOut myled(LED1);

double multiplier = 500.0;  // maximum on-off time in milliseconds
Timer timer;


int delay = 500; // initial on-off time in milliseconds

void random_on_off() {
         srand(unsigned(timer.read_ms()% RAND_MAX));
         delay = int(multiplier * float(rand()) / RAND_MAX);
         }

int main() {
    timer.start();
    while(1) {
        myled = !myled;
        mybutton.fall(&random_on_off);
        wait_ms(delay);
        }            
    }