Yasushi TAUCHI
/
Sound_PWM_2
PWMによる音だし(疑似Sin波)
Revision 1:e1919d5190b3, committed 2011-12-29
- Comitter:
- yueee_yt
- Date:
- Thu Dec 29 06:06:16 2011 +0000
- Parent:
- 0:5a95bead7a47
- Commit message:
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Dec 26 12:58:19 2011 +0000 +++ b/main.cpp Thu Dec 29 06:06:16 2011 +0000 @@ -14,24 +14,24 @@ float m1; void sound_out(void) { - static float j=0; + static float j=0; j=j+m1; - if(j>180)j=j-180; + if (j>180)j=j-180; sp1.write(ms[(int)j]); } int main() { float mm[]={mC,mD,mE,mF,mG,mA,mB,mC*2}; int i; - for (i=0;i<180;i++) { + for (i=0; i<180; i++) { ms[i]=sin(2*3.1415*(float)i/180.0)/2.0+0.5; } - sp1.period_us(10); + sp1.period_us(10); + timer.attach_us(&sound_out,100); - for (i=0;i<sizeof(mm);i++) { + for (i=0; i<sizeof(mm); i++) { m1=mm[i]*180/10000; - timer.attach_us(&sound_out,100); wait(0.5f); } sp1.write(0.0f);