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

Files at this revision

API Documentation at this revision

Comitter:
nucleo
Date:
Tue May 20 00:47:38 2014 +0000
Commit message:
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.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 42458802c36f main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue May 20 00:47:38 2014 +0000
@@ -0,0 +1,27 @@
+#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);
+        }            
+    }
\ No newline at end of file
diff -r 000000000000 -r 42458802c36f mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue May 20 00:47:38 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/0b3ab51c8877
\ No newline at end of file