-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
122 lines (99 loc) · 3.23 KB
/
main.cpp
File metadata and controls
122 lines (99 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "mbed.h"
#include "Joystick.h"
#include "N5110.h"
#include "globals.h"
#include "menu.h"
#include "sprites.h"
#include "space.h"
#include "music.h"
#include "snake.h"
#include "maze.h"
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
void init();
Ticker ticker;
int main()
{
init();
ticker.attach(&timer_isr,150ms);
while (true) { //loop to show title screen tll buttonA is pressed
if (g_buttonA_flag) {
ThisThread::sleep_for(500ms);
g_buttonA_flag = 0;
printf(" start \n");
break;
}
}
game = menu(game);
while (1) {
lcd.clear();
//game = 3;
switch (game) {
case 0:{ //song menu
song = selectMusic(song);
while(song == 9 || song == 10 || song == 11){ //loop until song is selected
printf("change music mode %d \n", song);
if (song == 9) {
randomSong = !randomSong; //toggle random song
nextSong = false; //disable next song
printf("random song: %d", randomSong);
}
if (song == 10) {
nextSong = !nextSong; //toggle next song
randomSong = false; //disable random song
printf("next song: %d", nextSong);
}
if (song == 11) {
stopMusic = !stopMusic; //toggle stop music
printf("stop music: %d", stopMusic);
}
song = selectMusic(song); //returns to music menu
}
printf("song selected: %d ", song);
playMusic(song);
game = menu(game); //returns to main menu
break;
}
case 1: {
spaceGame();
game = menu(game);
break;
}
case 2: {
printf("entering maze game\n");
maze();
game = menu(game); //returns to main menu
break;
}
case 3: {
playSnake();
game = menu(game); //returns to main menu
break;
}
}
if (g_buttonA_flag) { //logic to go back to menu
g_buttonA_flag = 0;
game = menu(game);
printf(" buttonA pressed \n");
}
clockCounter++;
lcd.refresh();
ThisThread::sleep_for(20ms);
}
}
void init() {
joystick.init();
lcd.init(LPH7366_1); //initialise for LPH7366-1 LCD (Options are LPH7366_1 and LPH7366_6)
lcd.setContrast(0.55); //set contrast to 55%
lcd.setBrightness(0.9); //set brightness to 50% (utilises the PWM)
buttonA.rise(&buttonA_isr);
joystick_button.fall(&joystick_button_isr);
joystick_button.mode(PullUp);
buttonA.mode(PullDown);
buttonUP.mode(PullDown);
buttonDOWN.mode(PullDown);
lcd.drawSprite(0,0,48,84,(int *)titleScreen);
lcd.refresh();
}