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
Diff: sound.cpp
- Revision:
- 4:d61f6d186db0
- Parent:
- 1:2967eac08981
- Child:
- 5:614e3ac042df
--- a/sound.cpp Wed Feb 21 09:25:48 2018 +0000
+++ b/sound.cpp Wed Mar 07 10:57:16 2018 +0000
@@ -3,20 +3,39 @@
PwmOut spkr(p26);
-void _Initialize(void) {
+static void _Initialize(void) {
spkr=0.0;
}
-void _Process(void) {
- for (float i = 2000.0; i < 10000.0; i += 100) {
- spkr.period(1.0 / i);
- spkr = 0.5;
- wait(0.1);
+static void _Finalize(void) {
+ _Initialize();
+}
+
+static float _SoundRange = 2000.0;
+
+static void _ProcessInitialize(void) {
+ _SoundRange = 2000.0;
+}
+
+static bool _ProcessIsContinue(void) {
+ return _SoundRange < 10000.0;
+}
+
+static void _ProcessRunning(void) {
+ spkr.period(1.0 / _SoundRange);
+ spkr = 0.5;
+ wait(0.1);
+
+ _SoundRange += 100;
+}
+
+static void _Process(void) {
+ _ProcessInitialize();
+ while ( _ProcessIsContinue() ) {
+ _ProcessRunning();
}
}
-void _Finalize(void) {
- _Initialize();
-}
-
-COMMAND_DEFINE Command_sound = {"sound", 0x01, _Initialize, _Finalize, _Process};
\ No newline at end of file
+COMMAND_DEFINE Command_sound = {"sound", 0x01, _Initialize, _Finalize, _Process,
+ _ProcessInitialize, _ProcessIsContinue, _ProcessRunning
+};
\ No newline at end of file