Coursework
Piezo Class Reference
Class for the PWM Piezo speaker. More...
#include <Piezo.h>
Public Member Functions | |
| Piezo (PinName Pwmout) | |
| Constructor, Pin must be PWM capable. | |
| void | play (float, int) |
| Blocking function for playing sound of given frequency and duration in ms. | |
| void | playAsync (float, int) |
| Nonblocking function for playing sound of given frequency and duration in ms. | |
| void | stop () |
| Function for stopping all sounds. | |
Detailed Description
Class for the PWM Piezo speaker.
This class is using PWM to make sounds with piezo speaker. Currently tested with LPC1768.
Writen by: Jan Crha (TeaPack_CZ), 2016.
Last modified: 2016-10-01
Example:
#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); } }
Definition at line 51 of file Piezo.h.
Constructor & Destructor Documentation
| Piezo | ( | PinName | Pwmout ) |
Member Function Documentation
| void play | ( | float | frequency, |
| int | duration_ms | ||
| ) |
| void playAsync | ( | float | frequency, |
| int | duration_ms | ||
| ) |
Generated on Tue Aug 23 2022 22:47:18 by
1.7.2