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:
- 14:66a1965318cb
- Child:
- 16:7c612029d9c9
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/menu/Menu.cpp Tue May 19 09:11:48 2020 +0000
@@ -0,0 +1,123 @@
+#include "Menu.h"
+
+const int curs [5][5] =
+{
+ {0,0,1,0,0},
+ {0,0,1,0,0},
+ {1,1,0,1,1},
+ {0,0,1,0,0},
+ {0,0,1,0,0},
+};
+
+const int curs_2 [5][5] =
+{
+ {1,0,0,0,1},
+ {0,1,0,1,0},
+ {0,0,1,0,0},
+ {0,1,0,1,0},
+ {1,0,0,0,1},
+};
+
+
+Menu::Menu()
+{
+
+}
+
+Menu::~Menu()
+{
+
+}
+
+void Menu::init()
+{
+ option = 1;
+ _x = 1;
+ _y = 18;
+}
+
+int Menu::display(N5110 &lcd, Gamepad &pad)
+{
+
+ while ( pad.A_pressed() == false) {
+ lcd.clear();
+ lcd.setContrast( pad.read_pot1());
+
+ lcd.printString(" Main Menu ",0,0);
+ lcd.printString(" Play ",0,2);
+ lcd.printString(" Highscore ",0,3);
+ lcd.printString(" Instructions ",0,4);
+
+ update(pad);
+ draw(lcd);
+ lcd.refresh();
+
+ }
+ wait(0.2);
+ return option;
+}
+
+void Menu::draw(N5110 &lcd)
+{
+ lcd.drawSprite(_x,_y,5,5,(int*)curs);
+}
+
+void Menu::update(Gamepad &pad)
+{
+
+ Direction d = pad.get_direction();
+
+ if (d == S) {
+ option += 1;
+ } else if (d == SE) {
+ option += 1;
+ } else if (d == SW) {
+ option += 1;
+ } else if (d == N) {
+ option -= 1;
+ } else if (d == NE) {
+ option -= 1;
+ } else if (d == NW) {
+ option -= 1;
+ } else {
+ option = option;
+ }
+
+ if (option == 4){
+ option = 3;
+ }
+
+ if (option == 0){
+ option = 1;
+ }
+
+ if (option == 1){
+ _y = 17;
+ }
+
+ if (option == 2){
+ _y = 25;
+ }
+
+ if (option == 3){
+ _y = 33;
+ }
+
+ wait(0.2);
+}
+
+void Menu::instructions(N5110 &lcd, Gamepad &pad)
+{
+ while ( pad.B_pressed() == false) {
+ lcd.clear();
+
+ lcd.printString(" Instructions ",0,0);
+ lcd.printString("(move cursor ",0,2);
+ lcd.printString("with Joy-Stick",0,3);
+ lcd.printString(" shoot with A)",0,4);
+ lcd.printString("return press B",0,5);
+
+ lcd.refresh();
+ }
+ wait(0.1);
+}