ピン変化割り込み

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Kansuni
Date:
Thu May 14 08:30:47 2015 +0000
Commit message:
???????????????

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h 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 6bbe13e9f388 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu May 14 08:30:47 2015 +0000
@@ -0,0 +1,74 @@
+//*******************************************
+// 割り込みのサンプルプログラム
+//*******************************************
+
+//ヘッダファイル(もしくはライブラリ)をインクルード
+#include "mbed.h"
+#include "main.h"
+
+//デジタル出力ピン(LED)の指定
+DigitalOut Interrupt_LED1(dp9);
+DigitalOut Interrupt_LED2(dp10);
+DigitalOut Interrupt_LED3(dp11);
+DigitalOut myLED(LED1);
+
+//割り込み用ピンの指定(自動的に入力用に指定される)
+InterruptIn TactSwitch(dp26);
+
+int main(void){
+    
+    //初期設定(すべてのLEDを消灯しておく)
+    Interrupt_LED1 = LOW;
+    Interrupt_LED2 = LOW;
+    Interrupt_LED3 = LOW;
+    myLED = LOW;
+    
+    //立ち上がり割り込み(dp26がHIGHならここを割り込みで実行)
+    TactSwitch.rise(&LightFlash);
+    
+    while(1){
+        //メインLEDをチカチカさせる。割り込み動作中は止まる。
+        myLED = HIGH;
+        wait(0.5);
+        myLED = LOW;
+        wait(0.5);
+    }
+}
+
+//3連LEDを光らせる関数。プロトタイプ宣言はヘッダファイル内で行う。
+void LightFlash(){
+    
+    wait(0.01);
+    
+    //LEDを順に光らせる
+    Interrupt_LED1 = HIGH;
+    wait(0.01);
+    Interrupt_LED2 = LOW;
+    wait(0.01);
+    Interrupt_LED3 = LOW;
+    
+    wait(0.5);
+    
+    Interrupt_LED1 = LOW;
+    wait(0.01);
+    Interrupt_LED2 = HIGH;
+    wait(0.01);
+    Interrupt_LED3 = LOW;
+    
+    wait(0.5);
+    
+    Interrupt_LED1 = LOW;
+    wait(0.01);
+    Interrupt_LED2 = LOW;
+    wait(0.01);
+    Interrupt_LED3 = HIGH;
+    
+    wait(0.5);
+    
+    Interrupt_LED1 = LOW;
+    wait(0.01);
+    Interrupt_LED2 = LOW;
+    wait(0.01);
+    Interrupt_LED3 = LOW;
+    
+}
\ No newline at end of file
diff -r 000000000000 -r 6bbe13e9f388 main.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.h	Thu May 14 08:30:47 2015 +0000
@@ -0,0 +1,4 @@
+#define HIGH 1
+#define LOW  0
+
+void LightFlash();
\ No newline at end of file
diff -r 000000000000 -r 6bbe13e9f388 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu May 14 08:30:47 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/433970e64889
\ No newline at end of file