LEDの点滅や、ブザーのOn,Offの周期測定をおこなう。 搬送波の周期は測定できない(10ms周期以上のON,OFF)
Dependencies: AQM0802A DigitalSw mbed
Diff: testSound.cpp
- Revision:
- 3:2a8fdcc54c95
- Child:
- 5:f137bb7eeda6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/testSound.cpp Mon Jun 05 12:31:15 2017 +0000 @@ -0,0 +1,92 @@ +#include "mbed.h" +#include "testSound.h" + +void tickSound(void); +Ticker tickSounder; + +DigitalOut dbgSoundPort(p25); +DigitalOut testSound(p26); + +Timer timerTestSound; +bool brinkRequestSound = false; + + + +void testSoundInitalize(void) +{ + timerTestSound.start(); + timerTestSound.reset(); + brinkRequestSound = false; + + tickSounder.attach_us(&tickSound, 250); +} + +uint8_t brinkPositionSound = 0; // brinkPatternSound[][ここ] +uint16_t brinkPriodSound = 0; // 点滅時間 1/1 ([ms]/count) +bool testSoundLevel = false; // false:Off true:On +uint32_t brinkPatternSound[][2] = { + {1,100}, + {0,100}, + + {1,200}, + {0,200}, + + {1,300}, + {0,300}, + + {1,400}, + {0,400}, + + {1,500}, + {0,500}, + + {1,100}, + {0,200}, + + + + + {2,0} // end +}; + +void tickSound(void) +{ + dbgSoundPort = !dbgSoundPort; + if(testSoundLevel == true) { + testSound = !testSound; + } else { + testSound = 0; + } +} + + + +bool testSoundMain(bool request) +{ + if(brinkRequestSound == false) { + if(request == true) { + brinkRequestSound = true; + brinkPositionSound = 0; + testSoundLevel = brinkPatternSound[brinkPositionSound][0]; + brinkPriodSound = brinkPatternSound[brinkPositionSound][1]; + + timerTestSound.reset(); + } else { + // nothing + } + } else { + if(timerTestSound.read_ms() > brinkPriodSound) { + brinkPositionSound++; + if(brinkPatternSound[brinkPositionSound][0] == 2) { + testSoundLevel = 0; + brinkRequestSound = false; + } else { + testSoundLevel = brinkPatternSound[brinkPositionSound][0]; + brinkPriodSound = brinkPatternSound[brinkPositionSound][1]; + timerTestSound.reset(); + + } + } + } + return (brinkRequestSound); +} \ No newline at end of file