As a test of the audio amplifier, it is a test to make a sound effect in the program. オーディオアンプのテストとして、プログラムで効果音を作るテストです。
main.cpp@0:5231285a0c94, 2014-05-12 (annotated)
- Committer:
- jksoft
- Date:
- Mon May 12 13:52:38 2014 +0000
- Revision:
- 0:5231285a0c94
First edition
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:5231285a0c94 | 1 | #include "mbed.h" |
jksoft | 0:5231285a0c94 | 2 | |
jksoft | 0:5231285a0c94 | 3 | AnalogOut DACout(p18); |
jksoft | 0:5231285a0c94 | 4 | DigitalOut AMPEnable(p12); |
jksoft | 0:5231285a0c94 | 5 | DigitalIn SW1(p25); |
jksoft | 0:5231285a0c94 | 6 | DigitalIn SW2(p26); |
jksoft | 0:5231285a0c94 | 7 | |
jksoft | 0:5231285a0c94 | 8 | void wave(float volume , float fq , float time) |
jksoft | 0:5231285a0c94 | 9 | { |
jksoft | 0:5231285a0c94 | 10 | float w_time = 1.0 / fq; |
jksoft | 0:5231285a0c94 | 11 | |
jksoft | 0:5231285a0c94 | 12 | AMPEnable = 0; |
jksoft | 0:5231285a0c94 | 13 | for (float i=0; i<time / w_time; i++) { |
jksoft | 0:5231285a0c94 | 14 | DACout = volume; |
jksoft | 0:5231285a0c94 | 15 | wait(w_time/2); |
jksoft | 0:5231285a0c94 | 16 | DACout = 0.0; |
jksoft | 0:5231285a0c94 | 17 | wait(w_time/2); |
jksoft | 0:5231285a0c94 | 18 | } |
jksoft | 0:5231285a0c94 | 19 | AMPEnable = 1; |
jksoft | 0:5231285a0c94 | 20 | |
jksoft | 0:5231285a0c94 | 21 | } |
jksoft | 0:5231285a0c94 | 22 | |
jksoft | 0:5231285a0c94 | 23 | int main() { |
jksoft | 0:5231285a0c94 | 24 | SW1.mode(PullUp); |
jksoft | 0:5231285a0c94 | 25 | SW2.mode(PullUp); |
jksoft | 0:5231285a0c94 | 26 | |
jksoft | 0:5231285a0c94 | 27 | while(1) |
jksoft | 0:5231285a0c94 | 28 | { |
jksoft | 0:5231285a0c94 | 29 | if( SW1 == 0 ) |
jksoft | 0:5231285a0c94 | 30 | { |
jksoft | 0:5231285a0c94 | 31 | for( int i = 0 ; i < 10 ; i++ ) |
jksoft | 0:5231285a0c94 | 32 | { |
jksoft | 0:5231285a0c94 | 33 | wave( 0.2 , i * 500.0 , 0.2 ); |
jksoft | 0:5231285a0c94 | 34 | } |
jksoft | 0:5231285a0c94 | 35 | } |
jksoft | 0:5231285a0c94 | 36 | if( SW2 == 0 ) |
jksoft | 0:5231285a0c94 | 37 | { |
jksoft | 0:5231285a0c94 | 38 | wave( 0.2 , 2000.0 , 0.2 ); |
jksoft | 0:5231285a0c94 | 39 | wave( 0.2 , 1000.0 , 0.2 ); |
jksoft | 0:5231285a0c94 | 40 | } |
jksoft | 0:5231285a0c94 | 41 | } |
jksoft | 0:5231285a0c94 | 42 | } |