A class to play notes on a speaker using analog out See https://mbed.org/users/4180_1/notebook/using-a-speaker-for-audio-output/
Diff: main.cpp
- Revision:
- 0:1c8118ee4106
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Mon Jan 21 03:37:11 2013 +0000
@@ -0,0 +1,22 @@
+#include "mbed.h"
+// Audio output demo for speaker
+// Speaker Class demo - plays a note on the analog output pin
+// 32 data points on one sine wave cycle are precomputed,
+// scaled, stored in an array and
+// continuously output to the Digital to Analog convertor
+
+// add Speaker class and PlayNote
+// PlayNote args are frequency in hz (<=5000), duration in secs , and volume(0.0..1.0)
+#include "Speaker.h"
+
+int main()
+{
+// setup instance of new Speaker class, mySpeaker
+// the pin must be the AnalogOut pin - p18
+ Speaker mySpeaker(p18);
+ // loops forever playing two notes on speaker using analog samples
+ while(1) {
+ mySpeaker.PlayNote(969.0, 0.5, 1.0);
+ mySpeaker.PlayNote(800.0, 0.5, 1.0);
+ }
+}