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.
Fork of Audio by
Revision 0:899519c9dfe2, committed 2018-08-10
- Comitter:
- irsanjul
- Date:
- Fri Aug 10 09:11:17 2018 +0000
- Commit message:
- aaa
Changed in this revision
Audio.cpp | Show annotated file Show diff for this revision Revisions of this file |
Audio.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 899519c9dfe2 Audio.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Audio.cpp Fri Aug 10 09:11:17 2018 +0000 @@ -0,0 +1,38 @@ +#include "Audio.h" + +double nada[9] = {247, 262, 294, 330, 350, 392, 440, 494, 523}; + +Audio::Audio(PinName buzzer): out(buzzer) +{ +} + +void Audio::SetVolume(double volume) +{ + vol = volume; +} + +void Audio::SetDuration(unsigned int milisec) +{ + ms = milisec; +} + +void Audio::PlayNote(unsigned int angka) +{ + if(angka > 8) angka = 8; + + double Nada = nada[angka]; + PlayNote(Nada*4.24, ms, vol); +} + +void Audio::mute() +{ + out = 0; +} + +void Audio::PlayNote(double frequency, double duration, double volume) +{ + out.period(1.0/frequency); + out = volume/2.0; + wait_ms(duration); + out = 0.0; +} \ No newline at end of file
diff -r 000000000000 -r 899519c9dfe2 Audio.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Audio.h Fri Aug 10 09:11:17 2018 +0000 @@ -0,0 +1,52 @@ +/* + \\ library ini merupakan play audio menggunakan PWM dan buzzer + \\ terinspirasi dari https://developer.mbed.org/users/4180_1/notebook/using-a-speaker-for-audio-output/ +*/ + +#ifndef AUDIO_H +#define AUDIO_H + +#include "mbed.h" + +class Audio +{ +public: + Audio(PinName buzzer); + + /* + \\ Set Volume digunakan untuk menentukan Volume dari buzzer + \\ Parameter volume bernilai 0.0 - 2.0 + \\ 0.0 untuk mute dan 2.0 untuk full + */ + void SetVolume(double volume=0.5f); + + /* + \\ SetDuration digunakan untuk menentukan lamanya buzzer bunyi dalam satu siklus + \\ Parameter menggunakan tipe bilangan bulat dalam orde mili sekon + */ + void SetDuration(unsigned int milisec=1000); + + /* + \\ PlayNote digunakan untuk membunyikan buzzer sesuai dengan nada, + \\ Nada yang digunakan merupakan nada dasar do sampai si dengan c=do + \\ parameter angka merupakan perwujudan nada 0=diam, 1=do, 2=re, 3=mi, dst + */ + void PlayNote(unsigned int angka); + + /* + \\ PlayNote digunakan untuk membunyikan buzzer sesuai dengan nada, + \\ dimainkan dalam not huruf + \\ parameter huruf berupa const char * karena dapat + */ +// void PlayNote(const char * huruf); + + void PlayNote(double frequency, double duration, double volume); + + void mute(); +private: + PwmOut out; + double vol; + int ms; +}; + +#endif // AUDIO_H \ No newline at end of file