![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
DigitalOutによる音だし
main.cpp@0:e31efc30c819, 2011-12-26 (annotated)
- Committer:
- yueee_yt
- Date:
- Mon Dec 26 12:34:00 2011 +0000
- Revision:
- 0:e31efc30c819
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yueee_yt | 0:e31efc30c819 | 1 | #define mC 261.626 |
yueee_yt | 0:e31efc30c819 | 2 | #define mD 293.665 |
yueee_yt | 0:e31efc30c819 | 3 | #define mE 329.628 |
yueee_yt | 0:e31efc30c819 | 4 | #define mF 349.228 |
yueee_yt | 0:e31efc30c819 | 5 | #define mG 391.995 |
yueee_yt | 0:e31efc30c819 | 6 | #define mA 440.000 |
yueee_yt | 0:e31efc30c819 | 7 | #define mB 493.883 |
yueee_yt | 0:e31efc30c819 | 8 | |
yueee_yt | 0:e31efc30c819 | 9 | #include "mbed.h" |
yueee_yt | 0:e31efc30c819 | 10 | |
yueee_yt | 0:e31efc30c819 | 11 | DigitalOut sp1(p5); |
yueee_yt | 0:e31efc30c819 | 12 | Ticker timer; |
yueee_yt | 0:e31efc30c819 | 13 | |
yueee_yt | 0:e31efc30c819 | 14 | int oto=0; |
yueee_yt | 0:e31efc30c819 | 15 | |
yueee_yt | 0:e31efc30c819 | 16 | void tick(void) |
yueee_yt | 0:e31efc30c819 | 17 | { |
yueee_yt | 0:e31efc30c819 | 18 | sp1.write(oto); |
yueee_yt | 0:e31efc30c819 | 19 | oto=!oto; |
yueee_yt | 0:e31efc30c819 | 20 | } |
yueee_yt | 0:e31efc30c819 | 21 | |
yueee_yt | 0:e31efc30c819 | 22 | int main() { |
yueee_yt | 0:e31efc30c819 | 23 | float mm[]={mC,mD,mE,mF,mG,mA,mB,mC*2}; |
yueee_yt | 0:e31efc30c819 | 24 | int i; |
yueee_yt | 0:e31efc30c819 | 25 | for (i=0;i<sizeof(mm);i++) { |
yueee_yt | 0:e31efc30c819 | 26 | timer.attach(&tick,1.0/mm[i]/2.0); |
yueee_yt | 0:e31efc30c819 | 27 | wait(0.5f); |
yueee_yt | 0:e31efc30c819 | 28 | } |
yueee_yt | 0:e31efc30c819 | 29 | timer.detach(); |
yueee_yt | 0:e31efc30c819 | 30 | while(1); |
yueee_yt | 0:e31efc30c819 | 31 | } |