Advanced Click Buzzer example for Hexiwear featuring OLED Display and Touch

Dependencies:   Hexi_KW40Z Hexi_OLED_SSD1351 PWM_Tone_Library

This project demonstrates the use of the Mikroelektronika Click Buzzer module with hexiwear featuring Display and Touch

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-v2_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
Touch the Hexiwear Electrode located on the right below to the start icone

The buzzer will start play a melody of 32 tones

/media/uploads/GregC/hexi_click_buzzer-v2.jpg

Committer:
GregC
Date:
Fri Oct 07 22:43:31 2016 +0000
Revision:
0:ac3116125c60
Advanced Click Buzzer example for Hexiwear featuring OLED Display and Touch

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GregC 0:ac3116125c60 1 #include "mbed.h"
GregC 0:ac3116125c60 2 #include "pwm_tone.h"
GregC 0:ac3116125c60 3 #include "Hexi_OLED_SSD1351.h"
GregC 0:ac3116125c60 4 #include "images.h"
GregC 0:ac3116125c60 5 #include "Hexi_KW40Z.h"
GregC 0:ac3116125c60 6
GregC 0:ac3116125c60 7 // Pin connections
GregC 0:ac3116125c60 8 PwmOut Buzzer(PTA10); // Define the Buzzer Pinout (PWM Out)
GregC 0:ac3116125c60 9 SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // SSD1351 OLED Driver (MOSI,SCLK,POWER,CS,RST,DC)
GregC 0:ac3116125c60 10 KW40Z kw40z_device(PTE24, PTE25); // Instantiate the Hexi KW40Z Driver (UART TX, UART RX)
GregC 0:ac3116125c60 11
GregC 0:ac3116125c60 12 // Variables
GregC 0:ac3116125c60 13 float C_3 = 1000000/Do3,
GregC 0:ac3116125c60 14 Cs_3 = 1000000/Do3s,
GregC 0:ac3116125c60 15 D_3 = 1000000/Re3,
GregC 0:ac3116125c60 16 Ds_3 = 1000000/Re3s,
GregC 0:ac3116125c60 17 E_3 = 1000000/Mi3,
GregC 0:ac3116125c60 18 F_3 = 1000000/Fa3,
GregC 0:ac3116125c60 19 Fs_3 = 1000000/Fa3s,
GregC 0:ac3116125c60 20 G_3 = 1000000/So3,
GregC 0:ac3116125c60 21 Gs_3 = 1000000/So3s,
GregC 0:ac3116125c60 22 A_3 = 1000000/La3,
GregC 0:ac3116125c60 23 As_3 = 1000000/La3s,
GregC 0:ac3116125c60 24 B_3 = 1000000/Ti3,
GregC 0:ac3116125c60 25 C_4 = 1000000/Do4,
GregC 0:ac3116125c60 26 Cs_4 = 1000000/Do4s,
GregC 0:ac3116125c60 27 D_4 = 1000000/Re4,
GregC 0:ac3116125c60 28 Ds_4 = 1000000/Re4s,
GregC 0:ac3116125c60 29 E_4 = 1000000/Mi4,
GregC 0:ac3116125c60 30 F_4 = 1000000/Fa4,
GregC 0:ac3116125c60 31 Fs_4 = 1000000/Fa4s,
GregC 0:ac3116125c60 32 G_4 = 1000000/So4,
GregC 0:ac3116125c60 33 Gs_4 = 1000000/So4s,
GregC 0:ac3116125c60 34 A_4 = 1000000/La4,
GregC 0:ac3116125c60 35 As_4 = 1000000/La4s,
GregC 0:ac3116125c60 36 B_4 = 1000000/Ti4,
GregC 0:ac3116125c60 37 C_5 = 1000000/Do5,
GregC 0:ac3116125c60 38 Cs_5 = 1000000/Do5s,
GregC 0:ac3116125c60 39 D_5 = 1000000/Re5,
GregC 0:ac3116125c60 40 Ds_5 = 1000000/Re5s,
GregC 0:ac3116125c60 41 E_5 = 1000000/Mi5,
GregC 0:ac3116125c60 42 F_5 = 1000000/Fa5,
GregC 0:ac3116125c60 43 Fs_5 = 1000000/Fa5s,
GregC 0:ac3116125c60 44 G_5 = 1000000/So5,
GregC 0:ac3116125c60 45 Gs_5 = 1000000/So5s,
GregC 0:ac3116125c60 46 A_5 = 1000000/La5,
GregC 0:ac3116125c60 47 As_5 = 1000000/La5s,
GregC 0:ac3116125c60 48 B_5 = 1000000/Ti5;
GregC 0:ac3116125c60 49 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, 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:ac3116125c60 50 int tones_num = 32; // Auto performance
GregC 0:ac3116125c60 51 int i;
GregC 0:ac3116125c60 52 const uint8_t *image1; // Pointer for the image to be displayed
GregC 0:ac3116125c60 53
GregC 0:ac3116125c60 54 void ButtonLeft(void)
GregC 0:ac3116125c60 55 {
GregC 0:ac3116125c60 56 Tune(Buzzer, E_4, 4); //4 Octave E beat 4/16
GregC 0:ac3116125c60 57 }
GregC 0:ac3116125c60 58
GregC 0:ac3116125c60 59 void ButtonRight(void)
GregC 0:ac3116125c60 60 {
GregC 0:ac3116125c60 61 Tune(Buzzer, C_4, 4); //4 Octave C beat 4/16
GregC 0:ac3116125c60 62 wait_ms(250);
GregC 0:ac3116125c60 63 Tune(Buzzer, D_4, 4); //4 Octave D beat 4/16
GregC 0:ac3116125c60 64 wait_ms(250);
GregC 0:ac3116125c60 65 Tune(Buzzer, E_4, 4); //4 Octave E beat 4/16
GregC 0:ac3116125c60 66 wait_ms(250);
GregC 0:ac3116125c60 67
GregC 0:ac3116125c60 68 for(i=0; i<tones_num; i++)
GregC 0:ac3116125c60 69 {
GregC 0:ac3116125c60 70 Auto_tunes(Buzzer, tones[i], 4); // Auto performance
GregC 0:ac3116125c60 71 Stop_tunes(Buzzer);
GregC 0:ac3116125c60 72 }
GregC 0:ac3116125c60 73 }
GregC 0:ac3116125c60 74
GregC 0:ac3116125c60 75
GregC 0:ac3116125c60 76
GregC 0:ac3116125c60 77 // main() runs in its own thread in the OS
GregC 0:ac3116125c60 78 // (note the calls to Thread::wait below for delays)
GregC 0:ac3116125c60 79 int main()
GregC 0:ac3116125c60 80 {
GregC 0:ac3116125c60 81 kw40z_device.attach_buttonLeft(&ButtonLeft);
GregC 0:ac3116125c60 82 kw40z_device.attach_buttonRight(&ButtonRight);
GregC 0:ac3116125c60 83
GregC 0:ac3116125c60 84
GregC 0:ac3116125c60 85 image1 = Buzzer96; // Setting pointer location of the 96 by 96 pixel bitmap
GregC 0:ac3116125c60 86 oled.DrawImage(image1,0,0); // Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0
GregC 0:ac3116125c60 87
GregC 0:ac3116125c60 88 while (true)
GregC 0:ac3116125c60 89 {
GregC 0:ac3116125c60 90 Thread::wait(500);
GregC 0:ac3116125c60 91 }
GregC 0:ac3116125c60 92 }
GregC 0:ac3116125c60 93