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/

Dependencies:   mbed

main.cpp

Committer:
4180_1
Date:
2013-01-21
Revision:
0:1c8118ee4106

File content as of revision 0:1c8118ee4106:

#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);
    }
}