Makoto Kobayashi
/
test_buzzer
buzzer tset
main.cpp@0:3ff0d44c36b6, 2014-10-20 (annotated)
- Committer:
- neoqased
- Date:
- Mon Oct 20 11:12:50 2014 +0000
- Revision:
- 0:3ff0d44c36b6
buzzer test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
neoqased | 0:3ff0d44c36b6 | 1 | #include "mbed.h" |
neoqased | 0:3ff0d44c36b6 | 2 | |
neoqased | 0:3ff0d44c36b6 | 3 | DigitalOut buzzer(p18); //電子ブザー用デジタル出力 |
neoqased | 0:3ff0d44c36b6 | 4 | |
neoqased | 0:3ff0d44c36b6 | 5 | int Buzzer(int buzvar){ //電子ブザーを鳴らす関数 |
neoqased | 0:3ff0d44c36b6 | 6 | switch (buzvar){ |
neoqased | 0:3ff0d44c36b6 | 7 | /**************エラーを知らせるbeep**************/ |
neoqased | 0:3ff0d44c36b6 | 8 | case -1: //error * - - - - |
neoqased | 0:3ff0d44c36b6 | 9 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 10 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.3); |
neoqased | 0:3ff0d44c36b6 | 11 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.3); |
neoqased | 0:3ff0d44c36b6 | 12 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.3); |
neoqased | 0:3ff0d44c36b6 | 13 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.3); |
neoqased | 0:3ff0d44c36b6 | 14 | break; |
neoqased | 0:3ff0d44c36b6 | 15 | /**************エラーここまで**************/ |
neoqased | 0:3ff0d44c36b6 | 16 | case 0: //サウンドなし |
neoqased | 0:3ff0d44c36b6 | 17 | buzzer = 0; |
neoqased | 0:3ff0d44c36b6 | 18 | break; |
neoqased | 0:3ff0d44c36b6 | 19 | /**************状態を知らせるためのbeep**************/ |
neoqased | 0:3ff0d44c36b6 | 20 | case 1: // *(短) |
neoqased | 0:3ff0d44c36b6 | 21 | buzzer = 1; |
neoqased | 0:3ff0d44c36b6 | 22 | wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 23 | buzzer = 0; |
neoqased | 0:3ff0d44c36b6 | 24 | break; |
neoqased | 0:3ff0d44c36b6 | 25 | case 2: // * * |
neoqased | 0:3ff0d44c36b6 | 26 | buzzer = 1; |
neoqased | 0:3ff0d44c36b6 | 27 | wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 28 | buzzer = 0; |
neoqased | 0:3ff0d44c36b6 | 29 | wait(0.05); |
neoqased | 0:3ff0d44c36b6 | 30 | buzzer = 1; |
neoqased | 0:3ff0d44c36b6 | 31 | wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 32 | buzzer = 0; |
neoqased | 0:3ff0d44c36b6 | 33 | break; |
neoqased | 0:3ff0d44c36b6 | 34 | case 3: // -(長) |
neoqased | 0:3ff0d44c36b6 | 35 | buzzer = 1; |
neoqased | 0:3ff0d44c36b6 | 36 | wait(0.3); |
neoqased | 0:3ff0d44c36b6 | 37 | buzzer = 0; |
neoqased | 0:3ff0d44c36b6 | 38 | break; |
neoqased | 0:3ff0d44c36b6 | 39 | case 4: // - - |
neoqased | 0:3ff0d44c36b6 | 40 | buzzer = 1; |
neoqased | 0:3ff0d44c36b6 | 41 | wait(0.3); |
neoqased | 0:3ff0d44c36b6 | 42 | buzzer = 0; |
neoqased | 0:3ff0d44c36b6 | 43 | wait(0.3); |
neoqased | 0:3ff0d44c36b6 | 44 | buzzer = 1; |
neoqased | 0:3ff0d44c36b6 | 45 | wait(0.3); |
neoqased | 0:3ff0d44c36b6 | 46 | buzzer = 0; |
neoqased | 0:3ff0d44c36b6 | 47 | break; |
neoqased | 0:3ff0d44c36b6 | 48 | case 5: // --- |
neoqased | 0:3ff0d44c36b6 | 49 | buzzer = 1; |
neoqased | 0:3ff0d44c36b6 | 50 | wait(0.9); |
neoqased | 0:3ff0d44c36b6 | 51 | buzzer = 0; |
neoqased | 0:3ff0d44c36b6 | 52 | break; |
neoqased | 0:3ff0d44c36b6 | 53 | case 6: // * * * * * * * * * * |
neoqased | 0:3ff0d44c36b6 | 54 | for(int i = 0; i < 3; i++){ |
neoqased | 0:3ff0d44c36b6 | 55 | buzzer = 1; |
neoqased | 0:3ff0d44c36b6 | 56 | wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 57 | buzzer = 0; |
neoqased | 0:3ff0d44c36b6 | 58 | wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 59 | buzzer = 1; |
neoqased | 0:3ff0d44c36b6 | 60 | wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 61 | buzzer = 0; |
neoqased | 0:3ff0d44c36b6 | 62 | wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 63 | buzzer = 1; |
neoqased | 0:3ff0d44c36b6 | 64 | wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 65 | buzzer = 0; |
neoqased | 0:3ff0d44c36b6 | 66 | wait(0.3); |
neoqased | 0:3ff0d44c36b6 | 67 | } |
neoqased | 0:3ff0d44c36b6 | 68 | buzzer = 1; |
neoqased | 0:3ff0d44c36b6 | 69 | wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 70 | buzzer = 0; |
neoqased | 0:3ff0d44c36b6 | 71 | break; |
neoqased | 0:3ff0d44c36b6 | 72 | case 7: // **-* ** -* ** *** **** "finish" |
neoqased | 0:3ff0d44c36b6 | 73 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 74 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 75 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 76 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 77 | wait(0.2); |
neoqased | 0:3ff0d44c36b6 | 78 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 79 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 80 | wait(0.2); |
neoqased | 0:3ff0d44c36b6 | 81 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 82 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 83 | wait(0.2); |
neoqased | 0:3ff0d44c36b6 | 84 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 85 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 86 | wait(0.2); |
neoqased | 0:3ff0d44c36b6 | 87 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 88 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 89 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 90 | wait(0.2); |
neoqased | 0:3ff0d44c36b6 | 91 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 92 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 93 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 94 | buzzer = 1; wait(0.1); buzzer = 0; |
neoqased | 0:3ff0d44c36b6 | 95 | break; |
neoqased | 0:3ff0d44c36b6 | 96 | case 8: // *-*** -*- --* "オワリ" |
neoqased | 0:3ff0d44c36b6 | 97 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 98 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 99 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 100 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 101 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 102 | wait(0.2); |
neoqased | 0:3ff0d44c36b6 | 103 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 104 | buzzer = 1; wait(0.1); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 105 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 106 | wait(0.2); |
neoqased | 0:3ff0d44c36b6 | 107 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 108 | buzzer = 1; wait(0.3); buzzer = 0; wait(0.1); |
neoqased | 0:3ff0d44c36b6 | 109 | buzzer = 1; wait(0.1); buzzer = 0; |
neoqased | 0:3ff0d44c36b6 | 110 | break; |
neoqased | 0:3ff0d44c36b6 | 111 | /**************状態を知らせるためのbeepここまで**************/ |
neoqased | 0:3ff0d44c36b6 | 112 | default: //no sound |
neoqased | 0:3ff0d44c36b6 | 113 | buzzer = 0; |
neoqased | 0:3ff0d44c36b6 | 114 | break; |
neoqased | 0:3ff0d44c36b6 | 115 | } |
neoqased | 0:3ff0d44c36b6 | 116 | return 0; |
neoqased | 0:3ff0d44c36b6 | 117 | } |
neoqased | 0:3ff0d44c36b6 | 118 | |
neoqased | 0:3ff0d44c36b6 | 119 | |
neoqased | 0:3ff0d44c36b6 | 120 | int main() { |
neoqased | 0:3ff0d44c36b6 | 121 | int buzvar = 6; |
neoqased | 0:3ff0d44c36b6 | 122 | Buzzer(buzvar); |
neoqased | 0:3ff0d44c36b6 | 123 | } |