一階邏輯開根號計算,使用 ticker 每隔二秒執行一次 LED 閃爍,直到計算完成後恆亮

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
mbedschool
Date:
Sat Feb 14 04:56:34 2015 +0000
Commit message:
ticker

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 41518d1f552d main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Feb 14 04:56:34 2015 +0000
@@ -0,0 +1,24 @@
+#include "mbed.h"
+ 
+Ticker flipper;
+DigitalOut led1(LED1);
+bool c=false;
+void flip() {     
+    while (!c) {
+        led1 = !led1;
+    }
+    led1=1;
+}
+ 
+int main() {
+
+    flipper.attach(&flip, 2.0); // the address of the function to be attached (flip) and the interval (2 seconds)
+    // spin in a main loop. flipper will interrupt it to call flip
+    while(1) {
+        unsigned long n=100000000;
+        float x=0;
+        while(x*x <n)
+            x = x + 0.01 ;   
+        c=true;
+    }
+}
diff -r 000000000000 -r 41518d1f552d mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Feb 14 04:56:34 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e188a91d3eaa
\ No newline at end of file