![](/media/cache/profiles/90a82bf94b4c5981e7e68ff425e519f3.50x50_q85.jpg)
LEDの点滅や、ブザーのOn,Offの周期測定をおこなう。 搬送波の周期は測定できない(10ms周期以上のON,OFF)
Dependencies: AQM0802A DigitalSw mbed
testLed.cpp@1:d4291fd3a94c, 2017-05-20 (annotated)
- Committer:
- suupen
- Date:
- Sat May 20 12:23:42 2017 +0000
- Revision:
- 1:d4291fd3a94c
- Parent:
- 0:c5384fa0fc28
- Child:
- 2:f22110fb3925
????????????????????????????????;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
suupen | 0:c5384fa0fc28 | 1 | #include "mbed.h" |
suupen | 0:c5384fa0fc28 | 2 | #include "testLed.h" |
suupen | 0:c5384fa0fc28 | 3 | |
suupen | 1:d4291fd3a94c | 4 | void tick(void); |
suupen | 1:d4291fd3a94c | 5 | Ticker ticker; |
suupen | 1:d4291fd3a94c | 6 | DigitalOut myled3(LED3); |
suupen | 1:d4291fd3a94c | 7 | |
suupen | 0:c5384fa0fc28 | 8 | DigitalOut testLed(LED1); |
suupen | 0:c5384fa0fc28 | 9 | |
suupen | 0:c5384fa0fc28 | 10 | Timer timerTestLed; |
suupen | 0:c5384fa0fc28 | 11 | bool brinkRequest = false; |
suupen | 0:c5384fa0fc28 | 12 | |
suupen | 1:d4291fd3a94c | 13 | |
suupen | 1:d4291fd3a94c | 14 | |
suupen | 0:c5384fa0fc28 | 15 | void testLedInitalize(void) |
suupen | 0:c5384fa0fc28 | 16 | { |
suupen | 0:c5384fa0fc28 | 17 | timerTestLed.start(); |
suupen | 0:c5384fa0fc28 | 18 | timerTestLed.reset(); |
suupen | 0:c5384fa0fc28 | 19 | brinkRequest = false; |
suupen | 0:c5384fa0fc28 | 20 | |
suupen | 1:d4291fd3a94c | 21 | ticker.attach_us(&tick, 1000); |
suupen | 0:c5384fa0fc28 | 22 | } |
suupen | 0:c5384fa0fc28 | 23 | |
suupen | 0:c5384fa0fc28 | 24 | uint8_t brinkPosition = 0; // brinkPattern[][ここ] |
suupen | 0:c5384fa0fc28 | 25 | uint16_t brinkPriod = 0; // 点滅時間 1/1 ([ms]/count) |
suupen | 1:d4291fd3a94c | 26 | bool testLedLevel = false; // false:Off true:On |
suupen | 0:c5384fa0fc28 | 27 | uint32_t brinkPattern[][2] = { |
suupen | 0:c5384fa0fc28 | 28 | {1,100}, |
suupen | 0:c5384fa0fc28 | 29 | {0,100}, |
suupen | 1:d4291fd3a94c | 30 | |
suupen | 1:d4291fd3a94c | 31 | {1,500}, |
suupen | 1:d4291fd3a94c | 32 | {0,500}, |
suupen | 1:d4291fd3a94c | 33 | |
suupen | 0:c5384fa0fc28 | 34 | {1,100}, |
suupen | 0:c5384fa0fc28 | 35 | {0,100}, |
suupen | 1:d4291fd3a94c | 36 | |
suupen | 1:d4291fd3a94c | 37 | {1,500}, |
suupen | 1:d4291fd3a94c | 38 | {0,500}, |
suupen | 1:d4291fd3a94c | 39 | |
suupen | 0:c5384fa0fc28 | 40 | {1,100}, |
suupen | 0:c5384fa0fc28 | 41 | {0,100}, |
suupen | 1:d4291fd3a94c | 42 | |
suupen | 1:d4291fd3a94c | 43 | {1,500}, |
suupen | 1:d4291fd3a94c | 44 | {0,500}, |
suupen | 1:d4291fd3a94c | 45 | |
suupen | 0:c5384fa0fc28 | 46 | {1,100}, |
suupen | 0:c5384fa0fc28 | 47 | {0,100}, |
suupen | 1:d4291fd3a94c | 48 | |
suupen | 0:c5384fa0fc28 | 49 | {1,100}, |
suupen | 0:c5384fa0fc28 | 50 | {0,100}, |
suupen | 1:d4291fd3a94c | 51 | |
suupen | 1:d4291fd3a94c | 52 | {1,100}, |
suupen | 1:d4291fd3a94c | 53 | {0,500}, |
suupen | 1:d4291fd3a94c | 54 | |
suupen | 0:c5384fa0fc28 | 55 | {1,100}, |
suupen | 1:d4291fd3a94c | 56 | {0,500}, |
suupen | 1:d4291fd3a94c | 57 | |
suupen | 0:c5384fa0fc28 | 58 | {1,100}, |
suupen | 1:d4291fd3a94c | 59 | {0,500}, |
suupen | 1:d4291fd3a94c | 60 | |
suupen | 0:c5384fa0fc28 | 61 | {1,100}, |
suupen | 1:d4291fd3a94c | 62 | {0,500}, |
suupen | 1:d4291fd3a94c | 63 | |
suupen | 0:c5384fa0fc28 | 64 | {1,100}, |
suupen | 1:d4291fd3a94c | 65 | {0,500}, |
suupen | 1:d4291fd3a94c | 66 | |
suupen | 1:d4291fd3a94c | 67 | {1,500}, |
suupen | 1:d4291fd3a94c | 68 | {0,500}, |
suupen | 1:d4291fd3a94c | 69 | |
suupen | 1:d4291fd3a94c | 70 | |
suupen | 1:d4291fd3a94c | 71 | |
suupen | 0:c5384fa0fc28 | 72 | {2,0} // end |
suupen | 0:c5384fa0fc28 | 73 | }; |
suupen | 0:c5384fa0fc28 | 74 | |
suupen | 1:d4291fd3a94c | 75 | void tick(void) |
suupen | 1:d4291fd3a94c | 76 | { |
suupen | 1:d4291fd3a94c | 77 | myled3 = !myled3; |
suupen | 1:d4291fd3a94c | 78 | if(testLedLevel == true) { |
suupen | 1:d4291fd3a94c | 79 | testLed = !testLed; |
suupen | 1:d4291fd3a94c | 80 | } else { |
suupen | 1:d4291fd3a94c | 81 | testLed = 0; |
suupen | 1:d4291fd3a94c | 82 | } |
suupen | 1:d4291fd3a94c | 83 | } |
suupen | 1:d4291fd3a94c | 84 | |
suupen | 1:d4291fd3a94c | 85 | |
suupen | 1:d4291fd3a94c | 86 | |
suupen | 0:c5384fa0fc28 | 87 | bool testLedMain(bool request) |
suupen | 0:c5384fa0fc28 | 88 | { |
suupen | 0:c5384fa0fc28 | 89 | if(brinkRequest == false) { |
suupen | 0:c5384fa0fc28 | 90 | if(request == true) { |
suupen | 0:c5384fa0fc28 | 91 | brinkRequest = true; |
suupen | 0:c5384fa0fc28 | 92 | brinkPosition = 0; |
suupen | 1:d4291fd3a94c | 93 | testLedLevel = brinkPattern[brinkPosition][0]; |
suupen | 0:c5384fa0fc28 | 94 | brinkPriod = brinkPattern[brinkPosition][1]; |
suupen | 0:c5384fa0fc28 | 95 | |
suupen | 0:c5384fa0fc28 | 96 | timerTestLed.reset(); |
suupen | 0:c5384fa0fc28 | 97 | } else { |
suupen | 0:c5384fa0fc28 | 98 | // nothing |
suupen | 0:c5384fa0fc28 | 99 | } |
suupen | 0:c5384fa0fc28 | 100 | } else { |
suupen | 0:c5384fa0fc28 | 101 | if(timerTestLed.read_ms() > brinkPriod) { |
suupen | 0:c5384fa0fc28 | 102 | brinkPosition++; |
suupen | 0:c5384fa0fc28 | 103 | if(brinkPattern[brinkPosition][0] == 2) { |
suupen | 1:d4291fd3a94c | 104 | testLedLevel = 0; |
suupen | 0:c5384fa0fc28 | 105 | brinkRequest = false; |
suupen | 0:c5384fa0fc28 | 106 | } else { |
suupen | 1:d4291fd3a94c | 107 | testLedLevel = brinkPattern[brinkPosition][0]; |
suupen | 0:c5384fa0fc28 | 108 | brinkPriod = brinkPattern[brinkPosition][1]; |
suupen | 1:d4291fd3a94c | 109 | timerTestLed.reset(); |
suupen | 0:c5384fa0fc28 | 110 | |
suupen | 0:c5384fa0fc28 | 111 | } |
suupen | 0:c5384fa0fc28 | 112 | } |
suupen | 0:c5384fa0fc28 | 113 | } |
suupen | 0:c5384fa0fc28 | 114 | return (brinkRequest); |
suupen | 0:c5384fa0fc28 | 115 | } |