zzzz
Audio.h@1:931e45afbcb4, 2020-08-26 (annotated)
- Committer:
- mauuuuul
- Date:
- Wed Aug 26 19:45:22 2020 +0000
- Revision:
- 1:931e45afbcb4
- Parent:
- 0:6d2a1fb93e9e
zzzzzzzzz
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
irsanjul | 0:6d2a1fb93e9e | 1 | /* |
irsanjul | 0:6d2a1fb93e9e | 2 | \\ library ini merupakan play audio menggunakan PWM dan buzzer |
irsanjul | 0:6d2a1fb93e9e | 3 | \\ terinspirasi dari https://developer.mbed.org/users/4180_1/notebook/using-a-speaker-for-audio-output/ |
irsanjul | 0:6d2a1fb93e9e | 4 | */ |
irsanjul | 0:6d2a1fb93e9e | 5 | |
irsanjul | 0:6d2a1fb93e9e | 6 | #ifndef AUDIO_H |
irsanjul | 0:6d2a1fb93e9e | 7 | #define AUDIO_H |
irsanjul | 0:6d2a1fb93e9e | 8 | |
irsanjul | 0:6d2a1fb93e9e | 9 | #include "mbed.h" |
irsanjul | 0:6d2a1fb93e9e | 10 | |
irsanjul | 0:6d2a1fb93e9e | 11 | class Audio |
irsanjul | 0:6d2a1fb93e9e | 12 | { |
irsanjul | 0:6d2a1fb93e9e | 13 | public: |
irsanjul | 0:6d2a1fb93e9e | 14 | Audio(PinName buzzer); |
irsanjul | 0:6d2a1fb93e9e | 15 | |
irsanjul | 0:6d2a1fb93e9e | 16 | /* |
irsanjul | 0:6d2a1fb93e9e | 17 | \\ Set Volume digunakan untuk menentukan Volume dari buzzer |
irsanjul | 0:6d2a1fb93e9e | 18 | \\ Parameter volume bernilai 0.0 - 2.0 |
irsanjul | 0:6d2a1fb93e9e | 19 | \\ 0.0 untuk mute dan 2.0 untuk full |
irsanjul | 0:6d2a1fb93e9e | 20 | */ |
irsanjul | 0:6d2a1fb93e9e | 21 | void SetVolume(double volume=0.5f); |
irsanjul | 0:6d2a1fb93e9e | 22 | |
irsanjul | 0:6d2a1fb93e9e | 23 | /* |
irsanjul | 0:6d2a1fb93e9e | 24 | \\ SetDuration digunakan untuk menentukan lamanya buzzer bunyi dalam satu siklus |
irsanjul | 0:6d2a1fb93e9e | 25 | \\ Parameter menggunakan tipe bilangan bulat dalam orde mili sekon |
irsanjul | 0:6d2a1fb93e9e | 26 | */ |
irsanjul | 0:6d2a1fb93e9e | 27 | void SetDuration(unsigned int milisec=1000); |
irsanjul | 0:6d2a1fb93e9e | 28 | |
irsanjul | 0:6d2a1fb93e9e | 29 | /* |
irsanjul | 0:6d2a1fb93e9e | 30 | \\ PlayNote digunakan untuk membunyikan buzzer sesuai dengan nada, |
irsanjul | 0:6d2a1fb93e9e | 31 | \\ Nada yang digunakan merupakan nada dasar do sampai si dengan c=do |
irsanjul | 0:6d2a1fb93e9e | 32 | \\ parameter angka merupakan perwujudan nada 0=diam, 1=do, 2=re, 3=mi, dst |
irsanjul | 0:6d2a1fb93e9e | 33 | */ |
irsanjul | 0:6d2a1fb93e9e | 34 | void PlayNote(unsigned int angka); |
irsanjul | 0:6d2a1fb93e9e | 35 | |
irsanjul | 0:6d2a1fb93e9e | 36 | /* |
irsanjul | 0:6d2a1fb93e9e | 37 | \\ PlayNote digunakan untuk membunyikan buzzer sesuai dengan nada, |
irsanjul | 0:6d2a1fb93e9e | 38 | \\ dimainkan dalam not huruf |
irsanjul | 0:6d2a1fb93e9e | 39 | \\ parameter huruf berupa const char * karena dapat |
irsanjul | 0:6d2a1fb93e9e | 40 | */ |
irsanjul | 0:6d2a1fb93e9e | 41 | // void PlayNote(const char * huruf); |
irsanjul | 0:6d2a1fb93e9e | 42 | |
irsanjul | 0:6d2a1fb93e9e | 43 | void PlayNote(double frequency, double duration, double volume); |
irsanjul | 0:6d2a1fb93e9e | 44 | |
irsanjul | 0:6d2a1fb93e9e | 45 | void mute(); |
irsanjul | 0:6d2a1fb93e9e | 46 | private: |
mauuuuul | 1:931e45afbcb4 | 47 | // PwmOut out; |
mauuuuul | 1:931e45afbcb4 | 48 | PinName _out; |
irsanjul | 0:6d2a1fb93e9e | 49 | double vol; |
irsanjul | 0:6d2a1fb93e9e | 50 | int ms; |
irsanjul | 0:6d2a1fb93e9e | 51 | }; |
irsanjul | 0:6d2a1fb93e9e | 52 | |
mauuuuul | 1:931e45afbcb4 | 53 | // ----------------------------------------------------------------------------- |
mauuuuul | 1:931e45afbcb4 | 54 | class MyAudio : public Audio |
mauuuuul | 1:931e45afbcb4 | 55 | { |
mauuuuul | 1:931e45afbcb4 | 56 | public: |
mauuuuul | 1:931e45afbcb4 | 57 | MyAudio(PinName buzz); |
mauuuuul | 1:931e45afbcb4 | 58 | void play(const int &code); |
mauuuuul | 1:931e45afbcb4 | 59 | |
mauuuuul | 1:931e45afbcb4 | 60 | private: |
mauuuuul | 1:931e45afbcb4 | 61 | void set(double dur=500, double vol=0.1); |
mauuuuul | 1:931e45afbcb4 | 62 | void playing(unsigned int note); |
mauuuuul | 1:931e45afbcb4 | 63 | void mute(); |
mauuuuul | 1:931e45afbcb4 | 64 | }; |
mauuuuul | 1:931e45afbcb4 | 65 | |
mauuuuul | 1:931e45afbcb4 | 66 | #endif // AUDIO_H |