淳熙 姜
/
Pin_Interrupt
ピン変化割り込み
main.cpp@0:6bbe13e9f388, 2015-05-14 (annotated)
- Committer:
- Kansuni
- Date:
- Thu May 14 08:30:47 2015 +0000
- Revision:
- 0:6bbe13e9f388
???????????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kansuni | 0:6bbe13e9f388 | 1 | //******************************************* |
Kansuni | 0:6bbe13e9f388 | 2 | // 割り込みのサンプルプログラム |
Kansuni | 0:6bbe13e9f388 | 3 | //******************************************* |
Kansuni | 0:6bbe13e9f388 | 4 | |
Kansuni | 0:6bbe13e9f388 | 5 | //ヘッダファイル(もしくはライブラリ)をインクルード |
Kansuni | 0:6bbe13e9f388 | 6 | #include "mbed.h" |
Kansuni | 0:6bbe13e9f388 | 7 | #include "main.h" |
Kansuni | 0:6bbe13e9f388 | 8 | |
Kansuni | 0:6bbe13e9f388 | 9 | //デジタル出力ピン(LED)の指定 |
Kansuni | 0:6bbe13e9f388 | 10 | DigitalOut Interrupt_LED1(dp9); |
Kansuni | 0:6bbe13e9f388 | 11 | DigitalOut Interrupt_LED2(dp10); |
Kansuni | 0:6bbe13e9f388 | 12 | DigitalOut Interrupt_LED3(dp11); |
Kansuni | 0:6bbe13e9f388 | 13 | DigitalOut myLED(LED1); |
Kansuni | 0:6bbe13e9f388 | 14 | |
Kansuni | 0:6bbe13e9f388 | 15 | //割り込み用ピンの指定(自動的に入力用に指定される) |
Kansuni | 0:6bbe13e9f388 | 16 | InterruptIn TactSwitch(dp26); |
Kansuni | 0:6bbe13e9f388 | 17 | |
Kansuni | 0:6bbe13e9f388 | 18 | int main(void){ |
Kansuni | 0:6bbe13e9f388 | 19 | |
Kansuni | 0:6bbe13e9f388 | 20 | //初期設定(すべてのLEDを消灯しておく) |
Kansuni | 0:6bbe13e9f388 | 21 | Interrupt_LED1 = LOW; |
Kansuni | 0:6bbe13e9f388 | 22 | Interrupt_LED2 = LOW; |
Kansuni | 0:6bbe13e9f388 | 23 | Interrupt_LED3 = LOW; |
Kansuni | 0:6bbe13e9f388 | 24 | myLED = LOW; |
Kansuni | 0:6bbe13e9f388 | 25 | |
Kansuni | 0:6bbe13e9f388 | 26 | //立ち上がり割り込み(dp26がHIGHならここを割り込みで実行) |
Kansuni | 0:6bbe13e9f388 | 27 | TactSwitch.rise(&LightFlash); |
Kansuni | 0:6bbe13e9f388 | 28 | |
Kansuni | 0:6bbe13e9f388 | 29 | while(1){ |
Kansuni | 0:6bbe13e9f388 | 30 | //メインLEDをチカチカさせる。割り込み動作中は止まる。 |
Kansuni | 0:6bbe13e9f388 | 31 | myLED = HIGH; |
Kansuni | 0:6bbe13e9f388 | 32 | wait(0.5); |
Kansuni | 0:6bbe13e9f388 | 33 | myLED = LOW; |
Kansuni | 0:6bbe13e9f388 | 34 | wait(0.5); |
Kansuni | 0:6bbe13e9f388 | 35 | } |
Kansuni | 0:6bbe13e9f388 | 36 | } |
Kansuni | 0:6bbe13e9f388 | 37 | |
Kansuni | 0:6bbe13e9f388 | 38 | //3連LEDを光らせる関数。プロトタイプ宣言はヘッダファイル内で行う。 |
Kansuni | 0:6bbe13e9f388 | 39 | void LightFlash(){ |
Kansuni | 0:6bbe13e9f388 | 40 | |
Kansuni | 0:6bbe13e9f388 | 41 | wait(0.01); |
Kansuni | 0:6bbe13e9f388 | 42 | |
Kansuni | 0:6bbe13e9f388 | 43 | //LEDを順に光らせる |
Kansuni | 0:6bbe13e9f388 | 44 | Interrupt_LED1 = HIGH; |
Kansuni | 0:6bbe13e9f388 | 45 | wait(0.01); |
Kansuni | 0:6bbe13e9f388 | 46 | Interrupt_LED2 = LOW; |
Kansuni | 0:6bbe13e9f388 | 47 | wait(0.01); |
Kansuni | 0:6bbe13e9f388 | 48 | Interrupt_LED3 = LOW; |
Kansuni | 0:6bbe13e9f388 | 49 | |
Kansuni | 0:6bbe13e9f388 | 50 | wait(0.5); |
Kansuni | 0:6bbe13e9f388 | 51 | |
Kansuni | 0:6bbe13e9f388 | 52 | Interrupt_LED1 = LOW; |
Kansuni | 0:6bbe13e9f388 | 53 | wait(0.01); |
Kansuni | 0:6bbe13e9f388 | 54 | Interrupt_LED2 = HIGH; |
Kansuni | 0:6bbe13e9f388 | 55 | wait(0.01); |
Kansuni | 0:6bbe13e9f388 | 56 | Interrupt_LED3 = LOW; |
Kansuni | 0:6bbe13e9f388 | 57 | |
Kansuni | 0:6bbe13e9f388 | 58 | wait(0.5); |
Kansuni | 0:6bbe13e9f388 | 59 | |
Kansuni | 0:6bbe13e9f388 | 60 | Interrupt_LED1 = LOW; |
Kansuni | 0:6bbe13e9f388 | 61 | wait(0.01); |
Kansuni | 0:6bbe13e9f388 | 62 | Interrupt_LED2 = LOW; |
Kansuni | 0:6bbe13e9f388 | 63 | wait(0.01); |
Kansuni | 0:6bbe13e9f388 | 64 | Interrupt_LED3 = HIGH; |
Kansuni | 0:6bbe13e9f388 | 65 | |
Kansuni | 0:6bbe13e9f388 | 66 | wait(0.5); |
Kansuni | 0:6bbe13e9f388 | 67 | |
Kansuni | 0:6bbe13e9f388 | 68 | Interrupt_LED1 = LOW; |
Kansuni | 0:6bbe13e9f388 | 69 | wait(0.01); |
Kansuni | 0:6bbe13e9f388 | 70 | Interrupt_LED2 = LOW; |
Kansuni | 0:6bbe13e9f388 | 71 | wait(0.01); |
Kansuni | 0:6bbe13e9f388 | 72 | Interrupt_LED3 = LOW; |
Kansuni | 0:6bbe13e9f388 | 73 | |
Kansuni | 0:6bbe13e9f388 | 74 | } |