main部分を作成しました(あくまで案です)
Dependencies: mbed
main.cpp@0:882f69fd7a02, 2016-01-15 (annotated)
- Committer:
- osakah
- Date:
- Fri Jan 15 06:15:27 2016 +0000
- Revision:
- 0:882f69fd7a02
main????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
osakah | 0:882f69fd7a02 | 1 | #include "mbed.h" |
osakah | 0:882f69fd7a02 | 2 | //出力先をLED1にする |
osakah | 0:882f69fd7a02 | 3 | DigitalOut myled(LED1); |
osakah | 0:882f69fd7a02 | 4 | //長点短点の長さはこうらしい |
osakah | 0:882f69fd7a02 | 5 | int dot = 0.3; |
osakah | 0:882f69fd7a02 | 6 | int dash = dot*3; |
osakah | 0:882f69fd7a02 | 7 | //プロトタイプ宣言 |
osakah | 0:882f69fd7a02 | 8 | int Signal(int TX); |
osakah | 0:882f69fd7a02 | 9 | //TX番号、状態 |
osakah | 0:882f69fd7a02 | 10 | int TX = 5; |
osakah | 0:882f69fd7a02 | 11 | int TXstate = 0; |
osakah | 0:882f69fd7a02 | 12 | |
osakah | 0:882f69fd7a02 | 13 | int main() { |
osakah | 0:882f69fd7a02 | 14 | while(1){ |
osakah | 0:882f69fd7a02 | 15 | //TXの状態TXstateで分岐 0:待機、1:アクティブ、2:メンテ etc... |
osakah | 0:882f69fd7a02 | 16 | //0,1の切り替えは時間経過で、0or1 ⇔ 2 の切り替えはボタンで?? |
osakah | 0:882f69fd7a02 | 17 | switch (TXstate){ |
osakah | 0:882f69fd7a02 | 18 | case 0 : |
osakah | 0:882f69fd7a02 | 19 | //待機 |
osakah | 0:882f69fd7a02 | 20 | break; |
osakah | 0:882f69fd7a02 | 21 | case 1 : |
osakah | 0:882f69fd7a02 | 22 | //アクティブ |
osakah | 0:882f69fd7a02 | 23 | Signal(TX); |
osakah | 0:882f69fd7a02 | 24 | break; |
osakah | 0:882f69fd7a02 | 25 | case 2 : |
osakah | 0:882f69fd7a02 | 26 | //メンテナンス |
osakah | 0:882f69fd7a02 | 27 | break; |
osakah | 0:882f69fd7a02 | 28 | default : |
osakah | 0:882f69fd7a02 | 29 | break; |
osakah | 0:882f69fd7a02 | 30 | } |
osakah | 0:882f69fd7a02 | 31 | |
osakah | 0:882f69fd7a02 | 32 | } |
osakah | 0:882f69fd7a02 | 33 | } |
osakah | 0:882f69fd7a02 | 34 | |
osakah | 0:882f69fd7a02 | 35 | //信号送信(現在はLチカ) |
osakah | 0:882f69fd7a02 | 36 | int Signal(TX) { |
osakah | 0:882f69fd7a02 | 37 | //M |
osakah | 0:882f69fd7a02 | 38 | myled = 1; |
osakah | 0:882f69fd7a02 | 39 | wait(dash); |
osakah | 0:882f69fd7a02 | 40 | myled = 0; |
osakah | 0:882f69fd7a02 | 41 | wait(dot); |
osakah | 0:882f69fd7a02 | 42 | myled = 1; |
osakah | 0:882f69fd7a02 | 43 | wait(dash); |
osakah | 0:882f69fd7a02 | 44 | myled = 0; |
osakah | 0:882f69fd7a02 | 45 | wait(dot*3); |
osakah | 0:882f69fd7a02 | 46 | |
osakah | 0:882f69fd7a02 | 47 | //O |
osakah | 0:882f69fd7a02 | 48 | myled = 1; |
osakah | 0:882f69fd7a02 | 49 | wait(dash); |
osakah | 0:882f69fd7a02 | 50 | myled = 0; |
osakah | 0:882f69fd7a02 | 51 | wait(dot); |
osakah | 0:882f69fd7a02 | 52 | myled = 1; |
osakah | 0:882f69fd7a02 | 53 | wait(dash); |
osakah | 0:882f69fd7a02 | 54 | myled = 0; |
osakah | 0:882f69fd7a02 | 55 | wait(dot); |
osakah | 0:882f69fd7a02 | 56 | myled = 1; |
osakah | 0:882f69fd7a02 | 57 | wait(dash); |
osakah | 0:882f69fd7a02 | 58 | myled = 0; |
osakah | 0:882f69fd7a02 | 59 | wait(dot*3); |
osakah | 0:882f69fd7a02 | 60 | |
osakah | 0:882f69fd7a02 | 61 | //number |
osakah | 0:882f69fd7a02 | 62 | for(i=0;i<TX;i++){ |
osakah | 0:882f69fd7a02 | 63 | myled = 1; |
osakah | 0:882f69fd7a02 | 64 | wait(dot); |
osakah | 0:882f69fd7a02 | 65 | myled = 0; |
osakah | 0:882f69fd7a02 | 66 | wait(dot); |
osakah | 0:882f69fd7a02 | 67 | } |
osakah | 0:882f69fd7a02 | 68 | for(i=0;i<6-TX;i++) wait(dot*2); |
osakah | 0:882f69fd7a02 | 69 | //Signal: (dot*4+dash*2)+(dot*5+dash*3)+dot*12 = dot*21+dash*5 = 10.8秒(メモ) |
osakah | 0:882f69fd7a02 | 70 | return0; |
osakah | 0:882f69fd7a02 | 71 | } |