Signal Generator
Dependencies: IniManager RA8875 Watchdog mbed-rtos mbed
Fork of speaker_demo_Analog by
main.cpp@0:1c8118ee4106, 2013-01-21 (annotated)
- Committer:
- 4180_1
- Date:
- Mon Jan 21 03:37:11 2013 +0000
- Revision:
- 0:1c8118ee4106
- Child:
- 1:dd07e1deec6c
ver 1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 0:1c8118ee4106 | 1 | #include "mbed.h" |
4180_1 | 0:1c8118ee4106 | 2 | // Audio output demo for speaker |
4180_1 | 0:1c8118ee4106 | 3 | // Speaker Class demo - plays a note on the analog output pin |
4180_1 | 0:1c8118ee4106 | 4 | // 32 data points on one sine wave cycle are precomputed, |
4180_1 | 0:1c8118ee4106 | 5 | // scaled, stored in an array and |
4180_1 | 0:1c8118ee4106 | 6 | // continuously output to the Digital to Analog convertor |
4180_1 | 0:1c8118ee4106 | 7 | |
4180_1 | 0:1c8118ee4106 | 8 | // add Speaker class and PlayNote |
4180_1 | 0:1c8118ee4106 | 9 | // PlayNote args are frequency in hz (<=5000), duration in secs , and volume(0.0..1.0) |
4180_1 | 0:1c8118ee4106 | 10 | #include "Speaker.h" |
4180_1 | 0:1c8118ee4106 | 11 | |
4180_1 | 0:1c8118ee4106 | 12 | int main() |
4180_1 | 0:1c8118ee4106 | 13 | { |
4180_1 | 0:1c8118ee4106 | 14 | // setup instance of new Speaker class, mySpeaker |
4180_1 | 0:1c8118ee4106 | 15 | // the pin must be the AnalogOut pin - p18 |
4180_1 | 0:1c8118ee4106 | 16 | Speaker mySpeaker(p18); |
4180_1 | 0:1c8118ee4106 | 17 | // loops forever playing two notes on speaker using analog samples |
4180_1 | 0:1c8118ee4106 | 18 | while(1) { |
4180_1 | 0:1c8118ee4106 | 19 | mySpeaker.PlayNote(969.0, 0.5, 1.0); |
4180_1 | 0:1c8118ee4106 | 20 | mySpeaker.PlayNote(800.0, 0.5, 1.0); |
4180_1 | 0:1c8118ee4106 | 21 | } |
4180_1 | 0:1c8118ee4106 | 22 | } |