hi

Dependencies:   m3pimaze mbed

Committer:
parikhkathan
Date:
Tue Jul 17 02:11:33 2018 +0000
Revision:
1:7ca26e605828
Parent:
0:cce248cfb763
hi; a

Who changed what in which revision?

UserRevisionLine numberNew contents of line
parikhkathan 0:cce248cfb763 1
parikhkathan 1:7ca26e605828 2 /*
parikhkathan 1:7ca26e605828 3 * buzzer1:
parikhkathan 1:7ca26e605828 4 *
parikhkathan 1:7ca26e605828 5 * This example uses the OrangutanBuzzer library to play a series of notes
parikhkathan 1:7ca26e605828 6 * on the Orangutan's/3pi's buzzer. It also uses the OrangutanLCD library
parikhkathan 1:7ca26e605828 7 * to display the notes its playing, and it uses the OrangutanPushbuttons
parikhkathan 1:7ca26e605828 8 * library to allow the user to stop/reset the melody with the top
parikhkathan 1:7ca26e605828 9 * pushbutton.
parikhkathan 1:7ca26e605828 10 *
parikhkathan 1:7ca26e605828 11 * http://www.pololu.com/docs/0J20
parikhkathan 1:7ca26e605828 12 * http://www.pololu.com
parikhkathan 1:7ca26e605828 13 * http://forum.pololu.com
parikhkathan 1:7ca26e605828 14 */
parikhkathan 1:7ca26e605828 15
parikhkathan 1:7ca26e605828 16 #define MELODY_LENGTH 95
parikhkathan 1:7ca26e605828 17
parikhkathan 1:7ca26e605828 18 // These arrays take up a total of 285 bytes of RAM (out of a 1k limit)
parikhkathan 1:7ca26e605828 19 unsigned char note[MELODY_LENGTH] =
parikhkathan 1:7ca26e605828 20 {
parikhkathan 1:7ca26e605828 21 E(5), SILENT_NOTE, E(5), SILENT_NOTE, E(5), SILENT_NOTE, C(5), E(5),
parikhkathan 1:7ca26e605828 22 G(5), SILENT_NOTE, G(4), SILENT_NOTE,
parikhkathan 1:7ca26e605828 23
parikhkathan 1:7ca26e605828 24 C(5), G(4), SILENT_NOTE, E(4), A(4), B(4), B_FLAT(4), A(4), G(4),
parikhkathan 1:7ca26e605828 25 E(5), G(5), A(5), F(5), G(5), SILENT_NOTE, E(5), C(5), D(5), B(4),
parikhkathan 1:7ca26e605828 26
parikhkathan 1:7ca26e605828 27 C(5), G(4), SILENT_NOTE, E(4), A(4), B(4), B_FLAT(4), A(4), G(4),
parikhkathan 1:7ca26e605828 28 E(5), G(5), A(5), F(5), G(5), SILENT_NOTE, E(5), C(5), D(5), B(4),
parikhkathan 1:7ca26e605828 29
parikhkathan 1:7ca26e605828 30 SILENT_NOTE, G(5), F_SHARP(5), F(5), D_SHARP(5), E(5), SILENT_NOTE,
parikhkathan 1:7ca26e605828 31 G_SHARP(4), A(4), C(5), SILENT_NOTE, A(4), C(5), D(5),
parikhkathan 1:7ca26e605828 32
parikhkathan 1:7ca26e605828 33 SILENT_NOTE, G(5), F_SHARP(5), F(5), D_SHARP(5), E(5), SILENT_NOTE,
parikhkathan 1:7ca26e605828 34 C(6), SILENT_NOTE, C(6), SILENT_NOTE, C(6),
parikhkathan 1:7ca26e605828 35
parikhkathan 1:7ca26e605828 36 SILENT_NOTE, G(5), F_SHARP(5), F(5), D_SHARP(5), E(5), SILENT_NOTE,
parikhkathan 1:7ca26e605828 37 G_SHARP(4), A(4), C(5), SILENT_NOTE, A(4), C(5), D(5),
parikhkathan 1:7ca26e605828 38
parikhkathan 1:7ca26e605828 39 SILENT_NOTE, E_FLAT(5), SILENT_NOTE, D(5), C(5)
parikhkathan 1:7ca26e605828 40 };
parikhkathan 1:7ca26e605828 41
parikhkathan 1:7ca26e605828 42 unsigned int duration[MELODY_LENGTH] =
parikhkathan 0:cce248cfb763 43 {
parikhkathan 1:7ca26e605828 44 100, 25, 125, 125, 125, 125, 125, 250, 250, 250, 250, 250,
parikhkathan 1:7ca26e605828 45
parikhkathan 1:7ca26e605828 46 375, 125, 250, 375, 250, 250, 125, 250, 167, 167, 167, 250, 125, 125,
parikhkathan 1:7ca26e605828 47 125, 250, 125, 125, 375,
parikhkathan 1:7ca26e605828 48
parikhkathan 1:7ca26e605828 49 375, 125, 250, 375, 250, 250, 125, 250, 167, 167, 167, 250, 125, 125,
parikhkathan 1:7ca26e605828 50 125, 250, 125, 125, 375,
parikhkathan 1:7ca26e605828 51
parikhkathan 1:7ca26e605828 52 250, 125, 125, 125, 250, 125, 125, 125, 125, 125, 125, 125, 125, 125,
parikhkathan 1:7ca26e605828 53
parikhkathan 1:7ca26e605828 54 250, 125, 125, 125, 250, 125, 125, 200, 50, 100, 25, 500,
parikhkathan 1:7ca26e605828 55
parikhkathan 1:7ca26e605828 56 250, 125, 125, 125, 250, 125, 125, 125, 125, 125, 125, 125, 125, 125,
parikhkathan 1:7ca26e605828 57
parikhkathan 1:7ca26e605828 58 250, 250, 125, 375, 500
parikhkathan 1:7ca26e605828 59 };
parikhkathan 1:7ca26e605828 60
parikhkathan 1:7ca26e605828 61 unsigned char currentIdx;
parikhkathan 1:7ca26e605828 62
parikhkathan 1:7ca26e605828 63 int main() // run once, when the sketch starts
parikhkathan 1:7ca26e605828 64 {
parikhkathan 1:7ca26e605828 65 currentIdx = 0;
parikhkathan 1:7ca26e605828 66 print("Music!");
parikhkathan 1:7ca26e605828 67
parikhkathan 1:7ca26e605828 68 while(1) // run over and over again
parikhkathan 1:7ca26e605828 69 {
parikhkathan 1:7ca26e605828 70 // if we haven't finished playing the song and
parikhkathan 1:7ca26e605828 71 // the buzzer is ready for the next note, play the next note
parikhkathan 1:7ca26e605828 72 if (currentIdx < MELODY_LENGTH && !is_playing())
parikhkathan 1:7ca26e605828 73 {
parikhkathan 1:7ca26e605828 74 // play note at max volume
parikhkathan 1:7ca26e605828 75 play_note(note[currentIdx], duration[currentIdx], 15);
parikhkathan 1:7ca26e605828 76
parikhkathan 1:7ca26e605828 77 // optional LCD feedback (for fun)
parikhkathan 1:7ca26e605828 78 lcd_goto_xy(0, 1); // go to start of the second LCD line
parikhkathan 1:7ca26e605828 79 if(note[currentIdx] != 255) // display blank for rests
parikhkathan 1:7ca26e605828 80 print_long(note[currentIdx]); // print integer value of the current note
parikhkathan 1:7ca26e605828 81 print(" "); // overwrite any left over characters
parikhkathan 1:7ca26e605828 82 currentIdx++;
parikhkathan 1:7ca26e605828 83 }
parikhkathan 1:7ca26e605828 84
parikhkathan 1:7ca26e605828 85 // Insert some other useful code here...
parikhkathan 1:7ca26e605828 86 // the melody will play normally while the rest of your code executes
parikhkathan 1:7ca26e605828 87 // as long as it executes quickly enough to keep from inserting delays
parikhkathan 1:7ca26e605828 88 // between the notes.
parikhkathan 1:7ca26e605828 89
parikhkathan 1:7ca26e605828 90 // For example, let the top user pushbutton function as a stop/reset melody button
parikhkathan 1:7ca26e605828 91 if (button_is_pressed(TOP_BUTTON))
parikhkathan 1:7ca26e605828 92 {
parikhkathan 1:7ca26e605828 93 stop_playing(); // silence the buzzer
parikhkathan 1:7ca26e605828 94 if (currentIdx < MELODY_LENGTH)
parikhkathan 1:7ca26e605828 95 currentIdx = MELODY_LENGTH; // terminate the melody
parikhkathan 1:7ca26e605828 96 else
parikhkathan 1:7ca26e605828 97 currentIdx = 0; // restart the melody
parikhkathan 1:7ca26e605828 98 wait_for_button_release(TOP_BUTTON); // wait here for the button to be released
parikhkathan 1:7ca26e605828 99 }
parikhkathan 1:7ca26e605828 100 }
parikhkathan 1:7ca26e605828 101
parikhkathan 1:7ca26e605828 102 return 0;
parikhkathan 1:7ca26e605828 103 }