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@5:614e3ac042df, 2018-03-14 (annotated)
- Committer:
- ksaito
- Date:
- Wed Mar 14 11:15:31 2018 +0000
- Revision:
- 5:614e3ac042df
- Parent:
- 4:d61f6d186db0
- Child:
- 9:35c816293400
????????
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 | 5:614e3ac042df | 32 | COMMAND_DEFINE Command_sound = {"sound", 0x01, _Initialize, _Finalize, |
| ksaito | 4:d61f6d186db0 | 33 | _ProcessInitialize, _ProcessIsContinue, _ProcessRunning |
| ksaito | 4:d61f6d186db0 | 34 | }; |