Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:42458802c36f
- Child:
- 1:61ebf06c61cc
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