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/
main.cpp
00001 #include "mbed.h" 00002 // Audio output demo for speaker 00003 // Speaker Class demo - plays a note on the analog output pin 00004 // 32 data points on one sine wave cycle are precomputed, 00005 // scaled, stored in an array and 00006 // continuously output to the Digital to Analog convertor 00007 00008 // add Speaker class and PlayNote 00009 // PlayNote args are frequency in hz (<=5000), duration in secs , and volume(0.0..1.0) 00010 #include "Speaker.h" 00011 00012 int main() 00013 { 00014 // setup instance of new Speaker class, mySpeaker 00015 // the pin must be the AnalogOut pin - p18 00016 Speaker mySpeaker(p18); 00017 // loops forever playing two notes on speaker using analog samples 00018 while(1) { 00019 mySpeaker.PlayNote(969.0, 0.5, 1.0); 00020 mySpeaker.PlayNote(800.0, 0.5, 1.0); 00021 } 00022 }
Generated on Tue Jul 12 2022 15:55:34 by 1.7.2