Simple Click Buzzer example for Hexiwear
Dependencies: PWM_Tone_Library
This project demonstrates the use of the Mikroelektronika Click Buzzer
module with hexiwear
Plug Hexiwear into the Docking Station and the BUZZER Click to the Click Socket 1
Connect the USB cable to your computer and to the micro-USB port of the Docking Station
Compile the project and copy the binary "Hexi_Click_Buzzer_Example_HEXIWEAR.bin" in the DAP-LINK drive
from your computer file explorer
Press the K64F-RESET button
on the docking station to start the program on your board
The buzzer will start play a melody of 32 tones
main.cpp@0:13eb53d1b502, 2016-09-20 (annotated)
- Committer:
- GregC
- Date:
- Tue Sep 20 23:21:55 2016 +0000
- Revision:
- 0:13eb53d1b502
Click Buzzer example for Hexiwear
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GregC | 0:13eb53d1b502 | 1 | #include "mbed.h" |
GregC | 0:13eb53d1b502 | 2 | #include "pwm_tone.h" |
GregC | 0:13eb53d1b502 | 3 | |
GregC | 0:13eb53d1b502 | 4 | PwmOut Buzzer(PTA10); |
GregC | 0:13eb53d1b502 | 5 | |
GregC | 0:13eb53d1b502 | 6 | float C_3 = 1000000/Do3, |
GregC | 0:13eb53d1b502 | 7 | Cs_3 = 1000000/Do3s, |
GregC | 0:13eb53d1b502 | 8 | D_3 = 1000000/Re3, |
GregC | 0:13eb53d1b502 | 9 | Ds_3 = 1000000/Re3s, |
GregC | 0:13eb53d1b502 | 10 | E_3 = 1000000/Mi3, |
GregC | 0:13eb53d1b502 | 11 | F_3 = 1000000/Fa3, |
GregC | 0:13eb53d1b502 | 12 | Fs_3 = 1000000/Fa3s, |
GregC | 0:13eb53d1b502 | 13 | G_3 = 1000000/So3, |
GregC | 0:13eb53d1b502 | 14 | Gs_3 = 1000000/So3s, |
GregC | 0:13eb53d1b502 | 15 | A_3 = 1000000/La3, |
GregC | 0:13eb53d1b502 | 16 | As_3 = 1000000/La3s, |
GregC | 0:13eb53d1b502 | 17 | B_3 = 1000000/Ti3, |
GregC | 0:13eb53d1b502 | 18 | C_4 = 1000000/Do4, |
GregC | 0:13eb53d1b502 | 19 | Cs_4 = 1000000/Do4s, |
GregC | 0:13eb53d1b502 | 20 | D_4 = 1000000/Re4, |
GregC | 0:13eb53d1b502 | 21 | Ds_4 = 1000000/Re4s, |
GregC | 0:13eb53d1b502 | 22 | E_4 = 1000000/Mi4, |
GregC | 0:13eb53d1b502 | 23 | F_4 = 1000000/Fa4, |
GregC | 0:13eb53d1b502 | 24 | Fs_4 = 1000000/Fa4s, |
GregC | 0:13eb53d1b502 | 25 | G_4 = 1000000/So4, |
GregC | 0:13eb53d1b502 | 26 | Gs_4 = 1000000/So4s, |
GregC | 0:13eb53d1b502 | 27 | A_4 = 1000000/La4, |
GregC | 0:13eb53d1b502 | 28 | As_4 = 1000000/La4s, |
GregC | 0:13eb53d1b502 | 29 | B_4 = 1000000/Ti4, |
GregC | 0:13eb53d1b502 | 30 | C_5 = 1000000/Do5, |
GregC | 0:13eb53d1b502 | 31 | Cs_5 = 1000000/Do5s, |
GregC | 0:13eb53d1b502 | 32 | D_5 = 1000000/Re5, |
GregC | 0:13eb53d1b502 | 33 | Ds_5 = 1000000/Re5s, |
GregC | 0:13eb53d1b502 | 34 | E_5 = 1000000/Mi5, |
GregC | 0:13eb53d1b502 | 35 | F_5 = 1000000/Fa5, |
GregC | 0:13eb53d1b502 | 36 | Fs_5 = 1000000/Fa5s, |
GregC | 0:13eb53d1b502 | 37 | G_5 = 1000000/So5, |
GregC | 0:13eb53d1b502 | 38 | Gs_5 = 1000000/So5s, |
GregC | 0:13eb53d1b502 | 39 | A_5 = 1000000/La5, |
GregC | 0:13eb53d1b502 | 40 | As_5 = 1000000/La5s, |
GregC | 0:13eb53d1b502 | 41 | B_5 = 1000000/Ti5; |
GregC | 0:13eb53d1b502 | 42 | |
GregC | 0:13eb53d1b502 | 43 | int tones[] = {E_4, D_4, C_4, D_4, E_4, E_4, E_4, 0, D_4, D_4, D_4, 0, E_4, G_4, G_4, 0, |
GregC | 0:13eb53d1b502 | 44 | E_4, D_4, C_4, D_4, E_4, E_4, E_4, 0, D_4, D_4, E_4, D_4, C_4, 0, 0, 0}; |
GregC | 0:13eb53d1b502 | 45 | int tones_num = 32; // Auto performance |
GregC | 0:13eb53d1b502 | 46 | |
GregC | 0:13eb53d1b502 | 47 | |
GregC | 0:13eb53d1b502 | 48 | int i; |
GregC | 0:13eb53d1b502 | 49 | |
GregC | 0:13eb53d1b502 | 50 | // main() runs in its own thread in the OS |
GregC | 0:13eb53d1b502 | 51 | // (note the calls to Thread::wait below for delays) |
GregC | 0:13eb53d1b502 | 52 | int main() { |
GregC | 0:13eb53d1b502 | 53 | |
GregC | 0:13eb53d1b502 | 54 | Tune(Buzzer, C_4, 4); //4 Octave C beat 4/16 |
GregC | 0:13eb53d1b502 | 55 | wait_ms(250); |
GregC | 0:13eb53d1b502 | 56 | Tune(Buzzer, D_4, 4); //4 Octave D beat 4/16 |
GregC | 0:13eb53d1b502 | 57 | wait_ms(250); |
GregC | 0:13eb53d1b502 | 58 | Tune(Buzzer, E_4, 4); //4 Octave E beat 4/16 |
GregC | 0:13eb53d1b502 | 59 | wait_ms(250); |
GregC | 0:13eb53d1b502 | 60 | |
GregC | 0:13eb53d1b502 | 61 | for(i=0; i<tones_num; i++) |
GregC | 0:13eb53d1b502 | 62 | { |
GregC | 0:13eb53d1b502 | 63 | Auto_tunes(Buzzer, tones[i], 4); // Auto performance |
GregC | 0:13eb53d1b502 | 64 | Stop_tunes(Buzzer); |
GregC | 0:13eb53d1b502 | 65 | } |
GregC | 0:13eb53d1b502 | 66 | } |
GregC | 0:13eb53d1b502 | 67 |