Simple tool for PWM piezo speaker
Piezo.h
- Committer:
- TeaPack_CZ
- Date:
- 2016-10-01
- Revision:
- 2:fa6d9a0b66fc
- Parent:
- 1:220d39711dc6
- Child:
- 3:df1e38c2c57b
File content as of revision 2:fa6d9a0b66fc:
#ifndef PIEZO #define PIEZO #include "mbed.h" /** Class for the PWM Piezo speaker. * This class is using PWM to make sounds with piezo speaker. * Currently tested with LPC1768.\n\n * * * Writen by: Jan Crha (TeaPack_CZ), 2016. * * Last modified: 2016-10-01 * * Example: * @code * #include "mbed.h" * #include "Piezo.h" * * Piezo PS(p21); * * int main(){ * int playTime = 120; * * for(int i=0; i<2; i++) * { * PS.play(466.16,playTime); * wait_ms(playTime); * PS.play(415.30,playTime); * wait_ms(playTime); * * PS.play(466.16,playTime); * wait_ms(playTime); * PS.play(349.23,playTime); * wait_ms(playTime); * * PS.play(277.18,playTime/2); * wait_ms(playTime/2); * PS.play(349.23,playTime/2); * wait_ms(playTime/2); * wait_ms(playTime); * PS.play(233.08,playTime/2); * wait_ms(playTime/2); * * wait_ms(playTime*4); * } * } * @endcode */ class Piezo { public: Piezo(PinName Pwmout); void play(float, int); void playAsync(float, int); void stop(); private: PwmOut _pwm; Ticker _timer; float Period; float min_freq; float max_freq; }; #endif