Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C12832 MMA7660 mbed
sound.cpp@4:d61f6d186db0, 2018-03-07 (annotated)
- Committer:
- ksaito
- Date:
- Wed Mar 07 10:57:16 2018 +0000
- Revision:
- 4:d61f6d186db0
- Parent:
- 1:2967eac08981
- Child:
- 5:614e3ac042df
???????????
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ksaito | 0:c3bc6981ad28 | 1 | #include "mbed.h" |
| ksaito | 1:2967eac08981 | 2 | #include "commands.h" |
| ksaito | 0:c3bc6981ad28 | 3 | |
| ksaito | 0:c3bc6981ad28 | 4 | PwmOut spkr(p26); |
| ksaito | 0:c3bc6981ad28 | 5 | |
| ksaito | 4:d61f6d186db0 | 6 | static void _Initialize(void) { |
| ksaito | 0:c3bc6981ad28 | 7 | spkr=0.0; |
| ksaito | 0:c3bc6981ad28 | 8 | } |
| ksaito | 0:c3bc6981ad28 | 9 | |
| ksaito | 4:d61f6d186db0 | 10 | static void _Finalize(void) { |
| ksaito | 4:d61f6d186db0 | 11 | _Initialize(); |
| ksaito | 4:d61f6d186db0 | 12 | } |
| ksaito | 4:d61f6d186db0 | 13 | |
| ksaito | 4:d61f6d186db0 | 14 | static float _SoundRange = 2000.0; |
| ksaito | 4:d61f6d186db0 | 15 | |
| ksaito | 4:d61f6d186db0 | 16 | static void _ProcessInitialize(void) { |
| ksaito | 4:d61f6d186db0 | 17 | _SoundRange = 2000.0; |
| ksaito | 4:d61f6d186db0 | 18 | } |
| ksaito | 4:d61f6d186db0 | 19 | |
| ksaito | 4:d61f6d186db0 | 20 | static bool _ProcessIsContinue(void) { |
| ksaito | 4:d61f6d186db0 | 21 | return _SoundRange < 10000.0; |
| ksaito | 4:d61f6d186db0 | 22 | } |
| ksaito | 4:d61f6d186db0 | 23 | |
| ksaito | 4:d61f6d186db0 | 24 | static void _ProcessRunning(void) { |
| ksaito | 4:d61f6d186db0 | 25 | spkr.period(1.0 / _SoundRange); |
| ksaito | 4:d61f6d186db0 | 26 | spkr = 0.5; |
| ksaito | 4:d61f6d186db0 | 27 | wait(0.1); |
| ksaito | 4:d61f6d186db0 | 28 | |
| ksaito | 4:d61f6d186db0 | 29 | _SoundRange += 100; |
| ksaito | 4:d61f6d186db0 | 30 | } |
| ksaito | 4:d61f6d186db0 | 31 | |
| ksaito | 4:d61f6d186db0 | 32 | static void _Process(void) { |
| ksaito | 4:d61f6d186db0 | 33 | _ProcessInitialize(); |
| ksaito | 4:d61f6d186db0 | 34 | while ( _ProcessIsContinue() ) { |
| ksaito | 4:d61f6d186db0 | 35 | _ProcessRunning(); |
| ksaito | 0:c3bc6981ad28 | 36 | } |
| ksaito | 0:c3bc6981ad28 | 37 | } |
| ksaito | 0:c3bc6981ad28 | 38 | |
| ksaito | 4:d61f6d186db0 | 39 | COMMAND_DEFINE Command_sound = {"sound", 0x01, _Initialize, _Finalize, _Process, |
| ksaito | 4:d61f6d186db0 | 40 | _ProcessInitialize, _ProcessIsContinue, _ProcessRunning |
| ksaito | 4:d61f6d186db0 | 41 | }; |