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.
Diff: main.cpp
- Revision:
- 2:225f68a31496
- Parent:
- 1:86ac6f8d9713
- Child:
- 3:b72b559aaee0
--- a/main.cpp Tue Apr 28 08:48:29 2015 +0000
+++ b/main.cpp Tue Apr 28 22:54:13 2015 +0000
@@ -11,12 +11,53 @@
#define PI 3.14159265
#define N_SAMPLES 15000
#define K 3.0
+#define K2 10.0
Ticker out;
short sample[ N_SAMPLES ];
float amp;
int count = 0;
float ci = 1.0;
+float base_tone;
+
+enum Tone_list {
+ Tone_A = 0,
+ Tone_Ais,
+ Tone_B,
+ Tone_C,
+ Tone_Cis,
+ Tone_D,
+ Tone_Dis,
+ Tone_E,
+ Tone_Eis,
+ Tone_F,
+ Tone_G,
+ Tone_Gis,
+};
+
+void init( void );
+void out_sample();
+
+int main() {
+
+ float ai;
+
+ init();
+
+ while(1) {
+ amp = key0 * 2.0;
+ ai = distanceSensor.rd();
+
+ ci = (2.25 - ai * 1.5);
+
+ if ( (0.95 < ci) && (ci < 1.05) )
+ led = 1;
+ else
+ led = 0;
+
+ wait( 0.001 );
+ }
+}
void init( void )
{
@@ -31,32 +72,15 @@
sample[ i ] = (float)i / (float)N_SAMPLES;
}
#endif
+
+ base_tone = (442.0 * pow( 2.0, (float)Tone_C / 12.0 )) /K2 * K;
+
+ i2c.frequency(400000);
+ out.attach( &out_sample, 1.0 / ((float)(N_SAMPLES / K) * K2) );
}
void out_sample()
{
ao = 0.5 + (amp * ((float)sample[ count % N_SAMPLES ] / 65536.0));
- count += (int)(52.3251 * K * ci);
+ count += (int)(base_tone * ci);
}
-
-
-int main() {
- init();
- i2c.frequency(400000);
- out.attach( &out_sample, 1.0 / ((float)(N_SAMPLES / K) * 10.0) );
- float ai;
- while(1) {
- ai = distanceSensor.rd();
-
-
- ci = (2.25 - ai * 1.5);
- amp = key0 * 2.0;
-
- if ( (0.95 < ci) && (ci < 1.05) )
- led = 1;
- else
- led = 0;
-
- wait( 0.001 );
- }
-}