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.
Dependencies: mbed
Diff: Menu/Menu.cpp
- Revision:
- 20:a8cad4e044ea
- Parent:
- 19:f35887b14c23
- Child:
- 21:20478f086bc2
--- a/Menu/Menu.cpp Mon Apr 15 18:49:35 2019 +0000 +++ b/Menu/Menu.cpp Tue Apr 16 19:19:43 2019 +0000 @@ -47,6 +47,9 @@ // Initialise at the highest level, starting state is the menu. _state = 1; _controller.init(); + _tone_flag = false; + _tone_counter = 0; + _tune_counter = 0; } void Menu::run(N5110 &lcd, Gamepad &gamepad) { @@ -103,6 +106,7 @@ lcd.printString("-Move down",0,3); lcd.printString("A:",0,4); lcd.printString("-Jump (back)",0,5); + play_tone(gamepad); } void Menu::display_menu(N5110 &lcd, Gamepad &gamepad) { @@ -115,4 +119,52 @@ lcd.printString("START- Play!",0,1); lcd.printString("X- Controls",0,2); lcd.drawSprite(1,25,23,80,(int*)menu_sprite); -} \ No newline at end of file + play_tone(gamepad); +} + +void Menu::play_tone(Gamepad &gamepad) { + _tone_flag = !_tone_flag; + _tone_counter++; + _tune_counter++; + if(_tune_counter < 12) { + play_tune_a(gamepad); + } else { + if(_tune_counter == 24) _tune_counter = 0; + play_tune_b(gamepad); + } + wait(0.14); +} + +void Menu::play_tune_a(Gamepad &gamepad) { + if(_tone_counter < 5) { + if(_tone_flag) { + gamepad.tone(220, 0.5); + } else { + gamepad.tone(440, 0.1); + } + } else { + if(_tone_counter == 6) _tone_counter = 0; + if(_tone_flag) { + gamepad.tone(174.61, 0.1); + } else { + gamepad.tone(246.94, 0.1); + } + } +} + +void Menu::play_tune_b(Gamepad &gamepad) { + if(_tone_counter < 5) { + if(_tone_flag) { + gamepad.tone(174.61, 0.5); + } else { + gamepad.tone(349.23, 0.1); + } + } else { + if(_tone_counter == 6) _tone_counter = 0; + if(_tone_flag) { + gamepad.tone(659.25, 0.1); + } else { + gamepad.tone(220, 0.1); + } + } +} \ No newline at end of file