Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Nucleo_piano by
Revision 6:58bab17100a2, committed 2018-07-03
- Comitter:
- aknin001
- Date:
- Tue Jul 03 03:29:59 2018 +0000
- Parent:
- 5:824785b64822
- Commit message:
- piano ok 4 octave, 8 notes, bug display better
Changed in this revision
TextLCD.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 824785b64822 -r 58bab17100a2 TextLCD.lib --- a/TextLCD.lib Tue Jul 03 02:06:44 2018 +0000 +++ b/TextLCD.lib Tue Jul 03 03:29:59 2018 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/users/Aliened/code/TextLCD_piano/#4276b56b4400 +https://os.mbed.com/users/aknin001/code/TextLCD/#4276b56b4400
diff -r 824785b64822 -r 58bab17100a2 main.cpp --- a/main.cpp Tue Jul 03 02:06:44 2018 +0000 +++ b/main.cpp Tue Jul 03 03:29:59 2018 +0000 @@ -35,47 +35,27 @@ void print_note(char *str) { - int i = 0; - int note = 0; - - lcd.cls(); - wait(0.000040f); - while (str[i]) - { - note = str[i]; - lcd.putc(note); - wait(0.000040f); - i++; - } +// lcd.cls(); + // wait(0.000040f); + lcd.printf("%s", str); } -//Thread thread; DigitalOut led1(LED1); -/**void print_thread() -{ - while (true) { - wait(1); - print_char(); - } -}**/ - void refresh_state_button() { - printf("refresh_state_button \n"); + //printf("refresh_state_button \n"); state_buttons = Bus_In & Bus_In.mask(); // read the bus and mask out bits not being used - printf("state_button [ %d ]\n", state_buttons); + //printf("state_button [ %d ]\n", state_buttons); } void play_music(int notes, double frequency) { - printf("play_music \n"); speaker.period(1.0 / frequency); while (state_buttons == notes) { refresh_state_button(); } - speaker = 0; } void check_buttons() @@ -84,21 +64,24 @@ int i = 0; char bufferOutput[30] = ""; - while (i < 8) + if (state_buttons == 0xFF) { - if (!(state_buttons & noteReference[i].mask)) { - frequency += noteReference[i].frequency * pow(2.0, gamme) + noteReference[i].add[gamme]; - strcat(bufferOutput, noteReference[i].name); - strcat(bufferOutput, " "); + speaker = 0; + lcd.cls(); + } + else { + while (i < 8) + { + if (!(state_buttons & noteReference[i].mask)) { + frequency += noteReference[i].frequency * pow(2.0, gamme) + noteReference[i].add[gamme]; + strcat(bufferOutput, noteReference[i].name); + strcat(bufferOutput, " "); + } + i++; } - strcat(bufferOutput, "\0"); - i++; - } - if (frequency > 0) { - speaker = 0.25; + speaker = 0.5; print_note(bufferOutput); play_music(state_buttons, frequency); - lcd.cls(); } } @@ -113,12 +96,13 @@ { //lcd.printf("%s\n", "CS435 Piano"); //wait(3); - speaker = 0; + while (true) { - printf("loop\n"); + //printf("loop\n"); led1 = !led1; refresh_state_button(); check_buttons(); wait(0.1); + lcd.cls(); } }