タイマー割込みのサンプルプログラム

Dependencies:   mbed

Revision:
0:53a95ad717d7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jul 29 04:45:54 2019 +0000
@@ -0,0 +1,36 @@
+#include "mbed.h"
+
+//Ticker flipper;
+DigitalOut led1(A0);
+DigitalOut led2(LED1);
+
+/*void flip(){
+    led2=!led2;
+    flipper.attach(&flip,2.0);
+}
+
+int main(){
+    led2 = 1;
+    flipper.attach(&flip,2.0);
+    while(1){
+        led1 = !led1;
+        wait(0.2);
+    }
+}*/
+
+
+Ticker flipper;
+
+void flip(){
+    led2=!led2; //LED is OFF
+    flipper.attach(&flip,2.0);
+}
+
+int main(){
+    led2 = 1;   //LED2 is ON
+    flipper.attach(&flip,2.0); // the address of the function to be attached (flip) and the interval (2 seconds)
+    while(1){
+        led1 = !led1;   //LED1は0.2sずつ点滅
+        wait(0.2);
+    }
+}