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.
Audio.h
00001 /* 00002 \\ library ini merupakan play audio menggunakan PWM dan buzzer 00003 \\ terinspirasi dari https://developer.mbed.org/users/4180_1/notebook/using-a-speaker-for-audio-output/ 00004 */ 00005 00006 #ifndef AUDIO_H 00007 #define AUDIO_H 00008 00009 #include "mbed.h" 00010 00011 class Audio 00012 { 00013 public: 00014 Audio(PinName buzzer); 00015 00016 /* 00017 \\ Set Volume digunakan untuk menentukan Volume dari buzzer 00018 \\ Parameter volume bernilai 0.0 - 2.0 00019 \\ 0.0 untuk mute dan 2.0 untuk full 00020 */ 00021 void SetVolume(double volume=0.5f); 00022 00023 /* 00024 \\ SetDuration digunakan untuk menentukan lamanya buzzer bunyi dalam satu siklus 00025 \\ Parameter menggunakan tipe bilangan bulat dalam orde mili sekon 00026 */ 00027 void SetDuration(unsigned int milisec=1000); 00028 00029 /* 00030 \\ PlayNote digunakan untuk membunyikan buzzer sesuai dengan nada, 00031 \\ Nada yang digunakan merupakan nada dasar do sampai si dengan c=do 00032 \\ parameter angka merupakan perwujudan nada 0=diam, 1=do, 2=re, 3=mi, dst 00033 */ 00034 void PlayNote(unsigned int angka); 00035 00036 /* 00037 \\ PlayNote digunakan untuk membunyikan buzzer sesuai dengan nada, 00038 \\ dimainkan dalam not huruf 00039 \\ parameter huruf berupa const char * karena dapat 00040 */ 00041 // void PlayNote(const char * huruf); 00042 00043 void PlayNote(double frequency, double duration, double volume); 00044 00045 void mute(); 00046 private: 00047 // PwmOut out; 00048 PinName _out; 00049 double vol; 00050 int ms; 00051 }; 00052 00053 // ----------------------------------------------------------------------------- 00054 class MyAudio : public Audio 00055 { 00056 public: 00057 MyAudio(PinName buzz); 00058 void play(const int &code); 00059 void playing(unsigned int note); 00060 00061 private: 00062 void set(double dur=500, double vol=0.1); 00063 void mute(); 00064 }; 00065 00066 #endif // AUDIO_H
Generated on Mon Aug 1 2022 04:18:18 by
1.7.2