Harshel Naik ECE department IUPUI / Mbed OS IotProject

Dependencies:   FXOS8700 Hexi_KW40Z PWM_Tone_Library_4th_Octave-6th_Octave

Fork of Hexi_Click_Buzzer_Example by Hexiwear

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers IotMain.cpp Source File

IotMain.cpp

00001 #include "mbed.h"
00002 #include "pwm_tone.h"
00003 #include "Hexi_OLED_SSD1351.h"
00004 
00005 #include "IotMainImage.h"
00006 #include "string.h"
00007 
00008 #include "Hexi_KW40Z.h"
00009 #include "FXOS8700.h"
00010 
00011 #define LED_ON      0
00012 #define LED_OFF     1
00013 
00014 
00015 /*------------------FUNCTIONS-------------------------------------------------*/
00016 
00017 //Defining functions for haptic feedback
00018 void StartHaptic(void);
00019 void StopHaptic(void const *n);
00020 
00021 //LED functions
00022 DigitalOut redLed(LED1);
00023 DigitalOut greenLed(LED2);
00024 DigitalOut blueLed(LED3);
00025 DigitalOut haptic(PTB9);
00026 
00027 // Pin connections
00028 DigitalOut led1(LED_GREEN); // RGB LED
00029 FXOS8700 accel(PTC11, PTC10);
00030 SSD1351 oled(PTB22,PTB21,PTC13,PTB20,PTE6, PTD15); // SSD1351 OLED Driver (MOSI,SCLK,POWER,CS,RST,DC)
00031 
00032 // Define the Buzzer Pinout (PWM Out)
00033 PwmOut Buzzer(PTA10);
00034 
00035 // Define timer for haptic feedback
00036 RtosTimer hapticTimer(StopHaptic, osTimerOnce);
00037 
00038 // Instantiate the Hexi KW40Z Driver (UART TX, UART RX)
00039 KW40Z kw40z_device(PTE24, PTE25);
00040 
00041 /*------------------VARIABLES-------------------------------------------------*/
00042 
00043 float C_3 =  1000000/Do3,                                                      
00044       Cs_3 = 1000000/Do3s,        
00045       D_3 =  1000000/Re3,                                                       
00046       Ds_3 = 1000000/Re3s,
00047       E_3 =  1000000/Mi3,
00048       F_3 =  1000000/Fa3,
00049       Fs_3 = 1000000/Fa3s,
00050       G_3 =  1000000/So3,
00051       Gs_3 = 1000000/So3s,
00052       A_3 =  1000000/La3,
00053       As_3 = 1000000/La3s,
00054       B_3 =  1000000/Ti3,
00055       C_4 =  1000000/Do4,
00056       Cs_4 = 1000000/Do4s,
00057       D_4 =  1000000/Re4,
00058       Ds_4 = 1000000/Re4s,
00059       E_4 =  1000000/Mi4,
00060       F_4 =  1000000/Fa4,
00061       Fs_4 = 1000000/Fa4s,
00062       G_4 =  1000000/So4,
00063       Gs_4 = 1000000/So4s,
00064       A_4 =  1000000/La4,
00065       As_4 = 1000000/La4s,
00066       B_4 =  1000000/Ti4,
00067       C_5 =  1000000/Do5,
00068       Cs_5 = 1000000/Do5s,
00069       D_5 =  1000000/Re5,
00070       Ds_5 = 1000000/Re5s,
00071       E_5 =  1000000/Mi5,
00072       F_5 =  1000000/Fa5,
00073       Fs_5 = 1000000/Fa5s,
00074       G_5 =  1000000/So5,
00075       Gs_5 = 1000000/So5s,
00076       A_5 =  1000000/La5,
00077       As_5 = 1000000/La5s,
00078       B_5 =  1000000/Ti5,
00079       C_6 =  1000000/Do6,  
00080       Cs_6 = 1000000/Do6s, 
00081       D_6  = 1000000/Re6,   
00082       Ds_6 = 1000000/Re6s,
00083       E_6  = 1000000/Mi6,
00084       F_6  = 1000000/Fa6,  
00085       Fs_6 = 1000000/Fa6s, 
00086       G_6  = 1000000/So6, 
00087       Gs_6 = 1000000/So6s,
00088       A_6  = 1000000/La6,  
00089       As_6 = 1000000/La6s, 
00090       B_6 =  1000000/Ti6;  
00091       
00092 //Notes defined by a million/defined value in pwm_tone.h file
00093 //Organize code such that all variables in .h file and all functions in seperate .cpp file for simpler debugging
00094 //Song tones-------------------------------------------------------------------
00095 
00096 //Marry had a little lamb red led, leftmost button
00097 int tones1[] = {E_4, D_4, C_4, D_4, E_4, E_4, E_4, 0,   D_4, D_4, D_4, 0,   \
00098                 E_4, G_4, G_4, 0,   E_4, D_4, C_4, D_4, E_4, E_4, E_4, 0,   \
00099                 D_4, D_4, E_4, D_4, C_4, 0,   0,   0};
00100                 //done
00101                 
00102 //Senya -Itachi theme 
00103 int tones2a[] = {G_5, Gs_5, G_5, Ds_5, F_5,  0, Ds_5, F_5, Ds_5, As_4, D_5, \
00104                  0};
00105                 //C_5(4), Ds_5(4), As_4(4), C_5(12)
00106                 //x3    
00107                  
00108 int tones2b[] = {C_5, D_5, Ds_5, D_5, C_5, As_4, C_5, D_5, F_5}; 
00109                 //Ds_5(12) 
00110                 //x3 twice as slow   
00111 
00112 int tones2c[] = {C_5, D_5, Ds_5, D_5, C_5, As_4, C_5, D_5, F_5, D_5};
00113                 //C_5(8) 
00114                 //x1 twice as slow
00115 
00116 
00117 
00118 
00119 
00120 int tones3[] = {As_3, A_3, Gs_3, G_3, Fs_3, F_3, E_3, Ds_3, D_3, Cs_3, C_3, 0,\
00121                 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
00122                };
00123                
00124 //OneRepublic -Secrets
00125 int tones4[] = {D_4, F_4, A_4, F_4, A_4, F_4, D_4, F_4, D_4, F_4, A_4, F_4, \
00126                 A_4, F_4, D_4, F_4, C_4, F_4, A_4, F_4, A_4, F_4, C_4, F_4, \
00127                 C_4, F_4, A_4, F_4, A_4, F_4, C_4, F_4, B_3, D_4, B_4, D_4, \
00128                 B_4, D_4, B_3, D_4, B_3, D_4, B_4, D_4, B_4, D_4, B_3, D_4, \
00129                 G_3, D_4, B_4, D_4, B_4, D_4, B_4, D_4, 0,   0,   A_4, A_4, \
00130                 A_4, A_4, A_4};  
00131                 //12 notes per row, done
00132                 
00133 //Number of tones---------------------------------------------------------------
00134 
00135 int tones_num1 = 32; // Auto performance, 32 notes max
00136 int tones_num2 = 63; // Auto performance, 23 notes max
00137 int tones_num3 = 12; // Auto performance, 12 notes max
00138 int tones_num4 = 9;  // Auto performance, 9 notes max  
00139 int i;
00140 Timer t;
00141 
00142 const uint8_t *image1; // Pointer for the image1 to be displayed
00143 char text1[20]; // Text Buffer for dynamic value displayed
00144 char text2[20]; // Text Buffer for dynamic value displayed
00145 char text3[20]; // Text Buffer for dynamic value displayed
00146 char text4[20]; // Text Buffer for dynamic value displayed
00147 char text5[20]; // Test Buffer for dynamic value displayed
00148 char text6[20]; // Text Buffer for dynamic value displayed
00149 
00150 /*------------------FUNCTIONS-------------------------------------------------*/
00151 
00152 //------------------RED LED-----------------------------------------------------
00153 void ButtonLeft(void)
00154 {
00155     StartHaptic();
00156     redLed      = LED_ON;
00157     greenLed    = LED_OFF;
00158     blueLed     = LED_OFF;
00159 
00160      // Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0
00161     oled.DrawImage(image1,0,0);
00162     oled_text_properties_t textProperties = {0};
00163     oled.GetTextProperties(&textProperties);
00164     
00165     /* Set text properties to white and right aligned for the dynamic text */
00166     textProperties.fontColor = COLOR_YELLOW;
00167     textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
00168     oled.SetTextProperties(&textProperties);
00169     /* Display text2 */
00170     strcpy((char *) text1,"When red LED");
00171     oled.Label((uint8_t *)text1,3,28);
00172     /* Display text3 */
00173     strcpy((char *) text2,"turns off, press"); //17 characters max length per statement
00174     oled.Label((uint8_t *)text2,3,41);
00175     /* Display text4 */
00176     strcpy((char *) text3,"another button");
00177     oled.Label((uint8_t *)text3,3,54);
00178     /* Display text5 */
00179     strcpy((char *) text4,"to play");
00180     oled.Label((uint8_t *)text4,3,67);
00181     /* Register callbacks to application functions */
00182     strcpy((char *)text5,"another song");
00183     oled.Label((uint8_t *)text5,3,80);
00184 
00185     for(i=0; i<tones_num1; i++) 
00186     {
00187         Auto_tunes(Buzzer, tones1[i], 4); // Auto performance
00188         Stop_tunes(Buzzer);
00189     }
00190     
00191     redLed      = LED_OFF;
00192     greenLed    = LED_OFF;
00193     blueLed     = LED_OFF;
00194 }
00195 //-------------------------GREEN LED--------------------------------------------
00196 void ButtonRight(void)
00197 {
00198     StartHaptic();
00199 
00200     redLed      = LED_OFF;
00201     greenLed    = LED_ON;
00202     blueLed     = LED_OFF;
00203 
00204     oled.DrawImage(image1,0,0);
00205     oled_text_properties_t textProperties = {0};
00206     oled.GetTextProperties(&textProperties);
00207     
00208     /* Set text properties to white and right aligned for the dynamic text */
00209     textProperties.fontColor = COLOR_YELLOW;
00210     textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
00211     oled.SetTextProperties(&textProperties);
00212     /* Display text2 */
00213     strcpy((char *) text1,"When green LED");
00214     oled.Label((uint8_t *)text1,3,28);
00215     /* Display text3 */
00216     strcpy((char *) text2,"turns off, press"); //17 characters max length per statement
00217     oled.Label((uint8_t *)text2,3,41);
00218     /* Display text4 */
00219     strcpy((char *) text3,"another button");
00220     oled.Label((uint8_t *)text3,3,54);
00221     /* Display text5 */
00222     strcpy((char *) text4,"to play");
00223     oled.Label((uint8_t *)text4,3,67);
00224     /* Register callbacks to application functions */
00225     strcpy((char *)text5,"another song");
00226     oled.Label((uint8_t *)text5,3,80);
00227 
00228     for(i=0; i<tones_num3; i++) 
00229     {
00230         Auto_tunes(Buzzer, tones2a[i], 4); // Auto performance
00231         Stop_tunes(Buzzer);
00232     }  
00233     Tune(Buzzer, C_5, 8);  //4 Octave C beat 4/16
00234     wait_ms(25);
00235     Tune(Buzzer, Ds_5, 8);  //4 Octave C beat 4/16
00236     wait_ms(25);
00237     Tune(Buzzer, As_4, 8);  //4 Octave C beat 4/16
00238     wait_ms(25);
00239     Tune(Buzzer, C_5, 20);
00240     wait_ms(250);
00241     
00242     for(i=0; i<tones_num3; i++) 
00243     {
00244         Auto_tunes(Buzzer, tones2a[i], 4); // Auto performance
00245         Stop_tunes(Buzzer);
00246     }  
00247     Tune(Buzzer, C_5, 8);  //4 Octave C beat 4/16
00248     wait_ms(25);
00249     Tune(Buzzer, Ds_5, 8);  //4 Octave C beat 4/16
00250     wait_ms(25);
00251     Tune(Buzzer, As_4, 8);  //4 Octave C beat 4/16
00252     wait_ms(25);
00253     Tune(Buzzer, C_5, 20);
00254     wait_ms(250);
00255     
00256     for(i=0; i<tones_num3; i++) 
00257     {
00258         Auto_tunes(Buzzer, tones2a[i], 4); // Auto performance
00259         Stop_tunes(Buzzer);
00260     }  
00261     Tune(Buzzer, C_5, 8);  //4 Octave C beat 4/16
00262     wait_ms(25);
00263     Tune(Buzzer, Ds_5, 8);  //4 Octave C beat 4/16
00264     wait_ms(25);
00265     Tune(Buzzer, As_4, 8);  //4 Octave C beat 4/16
00266     wait_ms(25);
00267     Tune(Buzzer, C_5, 20);
00268     wait_ms(250);
00269     
00270     for(i=0; i<tones_num4; i++) 
00271     {
00272         Auto_tunes(Buzzer, tones2b[i], 8); // Auto performance
00273         Stop_tunes(Buzzer);
00274     }
00275     Tune(Buzzer, Ds_5, 12);  //4 Octave C beat 4/16
00276     wait_ms(250); 
00277     
00278     for(i=0; i<tones_num4; i++) 
00279     {
00280         Auto_tunes(Buzzer, tones2b[i], 8); // Auto performance
00281         Stop_tunes(Buzzer);
00282     }
00283     Tune(Buzzer, Ds_5, 12);  //4 Octave C beat 4/16
00284     wait_ms(250);
00285     
00286     for(i=0; i<tones_num4; i++) 
00287     {
00288         Auto_tunes(Buzzer, tones2b[i], 8); // Auto performance
00289         Stop_tunes(Buzzer);
00290     }
00291     Tune(Buzzer, Ds_5, 12);  //4 Octave C beat 4/16
00292     wait_ms(250);
00293     
00294     for(i=0; i<tones_num4; i++) 
00295     {
00296         Auto_tunes(Buzzer, tones2c[i], 8); // Auto performance
00297         Stop_tunes(Buzzer);
00298     }
00299     Tune(Buzzer, C_5, 12);  //4 Octave C beat 4/16
00300     wait_ms(250);
00301     
00302     redLed      = LED_OFF;
00303     greenLed    = LED_OFF;
00304     blueLed     = LED_OFF;
00305 }
00306 //-------------------------BLUE LED---------------------------------------------
00307 void ButtonDown(void)
00308 {
00309     StartHaptic();
00310 
00311     redLed      = LED_OFF;
00312     greenLed    = LED_OFF;
00313     blueLed     = LED_ON;
00314 
00315     oled.DrawImage(image1,0,0);
00316     oled_text_properties_t textProperties = {0};
00317     oled.GetTextProperties(&textProperties);
00318     
00319     /* Set text properties to white and right aligned for the dynamic text */
00320     textProperties.fontColor = COLOR_YELLOW;
00321     textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
00322     oled.SetTextProperties(&textProperties);
00323     /* Display text2 */
00324     strcpy((char *) text1,"When blue LED");
00325     oled.Label((uint8_t *)text1,3,28);
00326     /* Display text3 */
00327     strcpy((char *) text2,"turns off, press"); //17 characters max length per statement
00328     oled.Label((uint8_t *)text2,3,41);
00329     /* Display text4 */
00330     strcpy((char *) text3,"another button");
00331     oled.Label((uint8_t *)text3,3,54);
00332     /* Display text5 */
00333     strcpy((char *) text4,"to play");
00334     oled.Label((uint8_t *)text4,3,67);
00335     /* Register callbacks to application functions */
00336     strcpy((char *)text5,"another song");
00337     oled.Label((uint8_t *)text5,3,80);
00338 
00339     Tune(Buzzer, 0, 4);    //1
00340     wait_ms(25);
00341     Tune(Buzzer, G_5, 2);  //2 
00342     wait_ms(25);
00343     Tune(Buzzer, G_5, 2);  //3 
00344     wait_ms(25);
00345     Tune(Buzzer, A_5, 4);  //4 
00346     wait_ms(25);
00347     Tune(Buzzer, G_5, 24); //5  
00348     wait_ms(25);
00349     Tune(Buzzer, A_5, 2);  //6
00350     wait_ms(25);
00351     Tune(Buzzer, G_5, 2);  //7
00352     wait_ms(25);
00353     Tune(Buzzer, A_5, 2);  //8
00354     wait_ms(25);
00355     Tune(Buzzer, G_5, 24); //9 
00356     wait_ms(25);
00357     Tune(Buzzer, G_5, 2);  //10
00358     wait_ms(25);
00359     Tune(Buzzer, G_5, 2);  //11
00360     wait_ms(25);
00361     Tune(Buzzer, C_6, 4);  //12
00362     wait_ms(25);
00363     Tune(Buzzer, B_5, 24); //13
00364     wait_ms(25);
00365     Tune(Buzzer, A_5, 2);  //14
00366     wait_ms(25);
00367     Tune(Buzzer, G_5, 2);  //15
00368     wait_ms(25);
00369     Tune(Buzzer, A_5, 6);  //16
00370     wait_ms(25);
00371     Tune(Buzzer, G_5, 18); //17
00372     wait_ms(25);
00373     Tune(Buzzer, G_5, 3);  //18
00374     wait_ms(25);
00375     Tune(Buzzer, A_5, 3);  //19
00376     wait_ms(25);
00377     Tune(Buzzer, G_5, 3);  //20
00378     wait_ms(25);
00379     Tune(Buzzer, D_6, 4);  //21
00380     wait_ms(25);
00381     Tune(Buzzer, Fs_6, 2); //22
00382     wait_ms(25);
00383     Tune(Buzzer, B_5, 10); //23
00384     wait_ms(25);
00385     Tune(Buzzer, G_5, 2);  //24
00386     wait_ms(25);
00387     Tune(Buzzer, G_5, 2);  //25
00388     wait_ms(25);
00389     Tune(Buzzer, A_5, 2);  //26
00390     wait_ms(25);
00391     Tune(Buzzer, G_5, 4);  //27
00392     wait_ms(25);
00393     Tune(Buzzer, C_6, 3);  //28
00394     wait_ms(25);
00395     Tune(Buzzer, E_5, 22); //29
00396     wait_ms(25);
00397     Tune(Buzzer, G_5, 2);  //30
00398     wait_ms(25);
00399     Tune(Buzzer, G_5, 2);  //31
00400     wait_ms(25);
00401     Tune(Buzzer, G_5, 2);  //32
00402     wait_ms(25);
00403     Tune(Buzzer, A_5, 2);  //33
00404     wait_ms(25);
00405     Tune(Buzzer, G_5, 4);  //34
00406     wait_ms(25);
00407     Tune(Buzzer, C_6, 4);  //35
00408     wait_ms(25);
00409     Tune(Buzzer, B_6, 10); //36
00410     wait_ms(25);
00411     Tune(Buzzer, G_5, 2);  //37
00412     wait_ms(25);
00413     Tune(Buzzer, G_5, 2);  //38
00414     wait_ms(25);
00415     Tune(Buzzer, G_5, 2);  //39
00416     wait_ms(25);
00417     Tune(Buzzer, G_5, 3);  //40
00418     wait_ms(25);
00419     Tune(Buzzer, A_5, 3);  //41
00420     wait_ms(25);
00421     Tune(Buzzer, G_5, 3);  //42
00422     wait_ms(25);
00423     Tune(Buzzer, A_5, 5);  //43
00424     wait_ms(25);
00425     Tune(Buzzer, G_5, 14); //44
00426     wait_ms(25);
00427     Tune(Buzzer, G_4, 2);  //45
00428     wait_ms(25);
00429     Tune(Buzzer, B_4, 4);  //46
00430     wait_ms(25);
00431     Tune(Buzzer, A_4, 4);  //47
00432     wait_ms(25);
00433     Tune(Buzzer, G_4, 4);  //48
00434     wait_ms(25);
00435     Tune(Buzzer, G_4, 4);  //49
00436     wait_ms(25);
00437     Tune(Buzzer, B_4, 2);  //50
00438     wait_ms(25);
00439     Tune(Buzzer, A_4, 4);  //51
00440     wait_ms(25);
00441     Tune(Buzzer, G_4, 6);  //52
00442     wait_ms(25);
00443     Tune(Buzzer, G_4, 2);  //53
00444     wait_ms(25);
00445     Tune(Buzzer, B_4, 2);  //54
00446     wait_ms(25);
00447     Tune(Buzzer, A_4, 4);  //55
00448     wait_ms(25);
00449     Tune(Buzzer, G_4, 6);  //56
00450     wait_ms(25);
00451     Tune(Buzzer, G_4, 2);  //57
00452     wait_ms(25);
00453     Tune(Buzzer, C_5, 4);  //58
00454     wait_ms(25);
00455     Tune(Buzzer, B_4, 4);  //59
00456     wait_ms(25);
00457     Tune(Buzzer, G_4, 4);  //60
00458     wait_ms(25);
00459     Tune(Buzzer, Fs_4, 6); //61
00460     wait_ms(25);
00461     Tune(Buzzer, G_4, 2);  //62
00462     wait_ms(25); 
00463     Tune(Buzzer, B_5, 4);  //63
00464     wait_ms(25); 
00465     Tune(Buzzer, B_4, 6);  //64
00466     wait_ms(25); 
00467     Tune(Buzzer, G_4, 4);  //65
00468     wait_ms(25); 
00469     Tune(Buzzer, C_5, 4);  //66
00470     wait_ms(25); 
00471     Tune(Buzzer, B_4, 2);  //67
00472     wait_ms(25); 
00473     Tune(Buzzer, B_4, 10); //68
00474     wait_ms(25); 
00475     Tune(Buzzer, A_4, 2);  //69
00476     wait_ms(25); 
00477     Tune(Buzzer, A_4, 4);  //70
00478     wait_ms(25); 
00479     Tune(Buzzer, A_4, 4);  //71
00480     wait_ms(25); 
00481     Tune(Buzzer, A_4, 6);  //72
00482     wait_ms(25); 
00483     Tune(Buzzer, A_4, 4);  //73
00484     wait_ms(25); 
00485     Tune(Buzzer, G_4, 4);  //74
00486     wait_ms(25); 
00487     Tune(Buzzer, A_4, 4);  //75
00488     wait_ms(25); 
00489     Tune(Buzzer, B_4, 4);  //76
00490     wait_ms(25); 
00491     Tune(Buzzer, A_4, 4);  //77
00492     wait_ms(25); 
00493     Tune(Buzzer, G_4, 4);  //78
00494     wait_ms(25); 
00495     Tune(Buzzer, G_4, 8);  //79
00496     wait_ms(25); 
00497     Tune(Buzzer, G_4, 8);  //80
00498     wait_ms(25); 
00499     Tune(Buzzer, 0, 4);    //81
00500     wait_ms(25); 
00501     Tune(Buzzer, B_4, 4);  //82
00502     wait_ms(25); 
00503     Tune(Buzzer, A_4, 4);  //83
00504     wait_ms(25); 
00505     Tune(Buzzer, G_4, 2);  //84
00506     wait_ms(25); 
00507     Tune(Buzzer, A_4, 2);  //85
00508     wait_ms(25);
00509     Tune(Buzzer, A_4, 8);  //86
00510     wait_ms(25); 
00511     Tune(Buzzer, A_4, 8);  //87
00512     wait_ms(25); 
00513     Tune(Buzzer, 0, 4);    //88
00514     wait_ms(25); 
00515     Tune(Buzzer, C_5, 4);  //89
00516     wait_ms(25); 
00517     Tune(Buzzer, B_4, 4);  //90
00518     wait_ms(25); 
00519     Tune(Buzzer, A_4, 2);  //91
00520     wait_ms(25); 
00521     Tune(Buzzer, B_4, 2);  //92
00522     wait_ms(25); 
00523     Tune(Buzzer, B_4, 8);  //93
00524     wait_ms(25); 
00525     Tune(Buzzer, B_4, 8);  //94
00526     wait_ms(25); 
00527     Tune(Buzzer, Fs_4, 8); //95
00528     wait_ms(25); 
00529     Tune(Buzzer, G_4, 4);  //96 
00530     wait_ms(25); 
00531     Tune(Buzzer, C_4, 20); //97
00532     wait_ms(25); 
00533     Tune(Buzzer, 0, 4);    //98
00534     wait_ms(25); 
00535     Tune(Buzzer, B_4, 4);  //99
00536     wait_ms(25); 
00537     Tune(Buzzer, A_4, 4);  //100
00538     wait_ms(25); 
00539     Tune(Buzzer, G_4, 4);  //101
00540     wait_ms(25); 
00541     Tune(Buzzer, G_4, 8);  //102
00542     wait_ms(25); 
00543     Tune(Buzzer, G_4, 8);  //103
00544     wait_ms(25); 
00545     Tune(Buzzer, G_4, 2);  //104
00546     wait_ms(25); 
00547     Tune(Buzzer, A_4, 2);  //105
00548     wait_ms(25); 
00549     Tune(Buzzer, B_4, 4);  //106
00550     wait_ms(25); 
00551     Tune(Buzzer, A_4, 4);  //107
00552     wait_ms(25); 
00553     Tune(Buzzer, G_4, 2);  //108
00554     wait_ms(25); 
00555     Tune(Buzzer, A_4, 2);  //109
00556     wait_ms(25); 
00557     Tune(Buzzer, A_4, 8);  //110
00558     wait_ms(25); 
00559     Tune(Buzzer, A_4, 8);  //111
00560     wait_ms(25); 
00561     Tune(Buzzer, 0, 4);    //112
00562     wait_ms(25); 
00563     Tune(Buzzer, B_4, 4);  //113
00564     wait_ms(25); 
00565     Tune(Buzzer, B_4, 4);  //114
00566     wait_ms(25); 
00567     Tune(Buzzer, A_4, 2);  //115
00568     wait_ms(25); 
00569     Tune(Buzzer, B_4, 2);  //116
00570     wait_ms(25); 
00571     Tune(Buzzer, B_4, 8);  //117
00572     wait_ms(25); 
00573     Tune(Buzzer, B_4, 8);  //118
00574     wait_ms(25); 
00575     Tune(Buzzer, A_4, 8);  //119
00576     wait_ms(25); 
00577     Tune(Buzzer, G_4, 4);  //120
00578     wait_ms(25); 
00579     Tune(Buzzer, G_4, 2);  //121
00580     wait_ms(25); 
00581     Tune(Buzzer, G_4, 2);  //122  
00582     wait_ms(25); 
00583     Tune(Buzzer, D_5, 4);  //123
00584     wait_ms(25);  
00585     Tune(Buzzer, D_4, 2);  //124
00586     wait_ms(25);  
00587     Tune(Buzzer, D_4, 2);  //125
00588     wait_ms(25);  
00589     Tune(Buzzer, B_4, 4);  //126
00590     wait_ms(25);  
00591     Tune(Buzzer, G_4, 2);  //127
00592     wait_ms(25);  
00593     Tune(Buzzer, D_5, 4);  //128
00594     wait_ms(25);  
00595     Tune(Buzzer, D_5, 4);  //129
00596     wait_ms(25);  
00597     Tune(Buzzer, D_5, 2);  //130
00598     wait_ms(25);  
00599     Tune(Buzzer, B_4, 6);  //131
00600     wait_ms(25);  
00601     Tune(Buzzer, G_4, 2);    //132
00602     wait_ms(25);  
00603     Tune(Buzzer, B_4, 16);  //133
00604     wait_ms(25);  
00605     Tune(Buzzer, A_4, 14);  //134
00606     wait_ms(25);  
00607     Tune(Buzzer, G_4, 2);  //135
00608     wait_ms(25);  
00609     Tune(Buzzer, A_4, 4);  //136
00610     wait_ms(25);  
00611     Tune(Buzzer, A_4, 4);  //137
00612     wait_ms(25);  
00613     Tune(Buzzer, A_4, 6);  //138
00614     wait_ms(25);  
00615     Tune(Buzzer, G_4, 2);  //139
00616     wait_ms(25);  
00617     Tune(Buzzer, A_4, 2);  //140
00618     wait_ms(25);  
00619     Tune(Buzzer, G_4, 2);  //141
00620     wait_ms(25);  
00621     Tune(Buzzer, B_4, 4);  //142
00622     wait_ms(25);  
00623     Tune(Buzzer, B_4, 4);  //143
00624     wait_ms(25);  
00625     Tune(Buzzer, G_4, 4);  //144
00626     wait_ms(25);  
00627     Tune(Buzzer, G_4, 32);  //145
00628     wait_ms(25);  
00629     Tune(Buzzer, D_4, 10);  //146
00630     wait_ms(25);  
00631     Tune(Buzzer, D_4, 8);  //147
00632     wait_ms(25);  
00633     
00634     
00635         
00636     redLed      = LED_OFF;
00637     greenLed    = LED_OFF;
00638     blueLed     = LED_OFF;
00639 }
00640 //-------------------------Yellow LED-------------------------------------------
00641 void ButtonUp(void)
00642 {
00643     StartHaptic();
00644 
00645     redLed      = LED_ON;
00646     greenLed    = LED_ON;
00647     blueLed     = LED_OFF;
00648 
00649     oled.DrawImage(image1,0,0);
00650     oled_text_properties_t textProperties = {0};
00651     oled.GetTextProperties(&textProperties);
00652     
00653         /* Set text properties to white and right aligned for the dynamic text */
00654         textProperties.fontColor = COLOR_YELLOW;
00655         textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
00656         oled.SetTextProperties(&textProperties);
00657         /* Display text2 */
00658         strcpy((char *) text1,"When yellow LED");
00659         oled.Label((uint8_t *)text1,3,28);
00660         /* Display text3 */
00661         strcpy((char *) text2,"turns off, press"); //17 characters max length per statement
00662         oled.Label((uint8_t *)text2,3,41);
00663         /* Display text4 */
00664         strcpy((char *) text3,"another button");
00665         oled.Label((uint8_t *)text3,3,54);
00666         /* Display text5 */
00667         strcpy((char *) text4,"to play");
00668         oled.Label((uint8_t *)text4,3,67);
00669         /* Register callbacks to application functions */
00670         strcpy((char *)text5,"another song");
00671         oled.Label((uint8_t *)text5,3,80);
00672 
00673     for(i=0; i<tones_num2; i++) 
00674     {
00675         Auto_tunes(Buzzer, tones4[i], 4); // Auto performance
00676         Stop_tunes(Buzzer);
00677     }
00678     Tune(Buzzer, A_4, 8);  //4 Octave F beat 4/16
00679     Tune(Buzzer, F_4, 16);  //4 Octave F beat 4/16
00680     wait_ms(250);
00681     
00682     redLed      = LED_OFF;
00683     greenLed    = LED_OFF;
00684     blueLed     = LED_OFF;
00685 }
00686 
00687 
00688 /*------------------MAIN------------------------------------------------------*/
00689 
00690 // main() runs in its own thread in the OS
00691 // (note the calls to Thread::wait below for delays)
00692 
00693 int main()
00694 {
00695     while(true)
00696     {
00697         // Setting pointer location of the 96 by 96 pixel bitmap
00698         image1  = Accelero;
00699         // Fill 96px by 96px Screen with 96px by 96px NXP Image starting at x=0,y=0
00700         oled.DrawImage(image1,0,0);
00701         
00702         redLed = LED_ON;
00703         greenLed = LED_OFF;
00704         blueLed = LED_OFF;
00705         wait(1);
00706         
00707         redLed = LED_OFF;
00708         greenLed = LED_ON;
00709         blueLed = LED_OFF;
00710         wait(1);
00711         
00712         redLed = LED_OFF;
00713         greenLed = LED_OFF;
00714         blueLed = LED_ON;
00715         wait(1);
00716         
00717         oled_text_properties_t textProperties = {0};
00718         oled.GetTextProperties(&textProperties);
00719         /* Set text properties to white and right aligned for the dynamic text */
00720         textProperties.fontColor = COLOR_YELLOW;
00721         textProperties.alignParam = OLED_TEXT_ALIGN_LEFT;
00722         oled.SetTextProperties(&textProperties);
00723         /* Display text2 */
00724         strcpy((char *) text1,"Hello! Press the ");
00725         oled.Label((uint8_t *)text1,3,28);
00726         /* Display text3 */
00727         strcpy((char *) text2,"the left, right, "); //17 characters max length per statement
00728         oled.Label((uint8_t *)text2,3,41);
00729         /* Display text4 */
00730         strcpy((char *) text3,"top, or bottom   ");
00731         oled.Label((uint8_t *)text3,3,54);
00732         /* Display text5 */
00733         strcpy((char *) text4,"buttons to play  ");
00734         oled.Label((uint8_t *)text4,3,67);
00735         /* Register callbacks to application functions */
00736         strcpy((char *)text5,"a song            ");
00737         oled.Label((uint8_t *)text5,3,80);
00738         
00739         kw40z_device.attach_buttonUp(&ButtonUp);
00740         kw40z_device.attach_buttonDown(&ButtonDown);
00741         kw40z_device.attach_buttonLeft(&ButtonLeft);
00742         kw40z_device.attach_buttonRight(&ButtonRight);
00743         while(true){
00744         Thread::wait(500);}
00745     }
00746 }
00747 
00748 void StartHaptic(void)
00749 {
00750     hapticTimer.start(50);
00751     haptic = 1;
00752 }
00753 
00754 void StopHaptic(void const *n)
00755 {
00756     haptic = 0;
00757     hapticTimer.stop();
00758 }