-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.ino
138 lines (129 loc) · 3.54 KB
/
menu.ino
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* LedTable
*
* Written by: Klaas De Craemer, Ing. David Hrbaty
*
* Menu system for the LED table
*/
#define MINSELECTION 1
#define MAXSELECTION 9
unsigned int curSelection = MINSELECTION;
#define TEXTSPEED 140
void mainLoop(void){
char* curSelectionText;
int curSelectionTextLength;
unsigned long prevUpdateTime = 0;
while(true){
//Show menu system and wait for input
clearTablePixels();
switch (curSelection){
case 1:
curSelectionText = "1 Rainbow";
curSelectionTextLength = 9;
break;
case 2:
curSelectionText = "2 Animation";
curSelectionTextLength = 11;
break;
case 3:
curSelectionText = "3 Stars";
curSelectionTextLength = 7;
break;
case 4:
curSelectionText = "4 Vu Meter";
curSelectionTextLength = 10;
break;
case 5:
curSelectionText = "5 Dice";
curSelectionTextLength = 6;
break;
case 6:
curSelectionText = "6 Tetris";
curSelectionTextLength = 8;
break;
case 7:
curSelectionText = "7 Snake";
curSelectionTextLength = 7;
break;
case 8:
curSelectionText = "8 Pong";
curSelectionTextLength = 6;
break;
case 9:
curSelectionText = "9 Bricks";
curSelectionTextLength = 8;
break;
}
boolean selectionChanged = false;
boolean runSelection = false;
//Scroll current selection text from right to left;
for (int x=FIELD_WIDTH; x>-(curSelectionTextLength*8); x--){
printText(curSelectionText, curSelectionTextLength, x, (FIELD_HEIGHT-8)/2, YELLOW);
//Read buttons
unsigned long curTime;
do{
readInput();
if (curControl != BTN_NONE){
if (curControl == BTN_LEFT){
curSelection--;
selectionChanged = true;
} else if (curControl == BTN_RIGHT){
curSelection++;
selectionChanged = true;
} else if (curControl == BTN_START){
runSelection = true;
}
checkSelectionRange();
}
curTime = millis();
} while (((curTime - prevUpdateTime) < TEXTSPEED) && (curControl == BTN_NONE));//Once enough time has passed, proceed
prevUpdateTime = curTime;
if (selectionChanged || runSelection)
break;
}
//If we are here, it means a selection was changed or a game started, or user did nothing
if (selectionChanged){
//For now, do nothing
} else if (runSelection){//Start selected game
switch (curSelection){
case 1:
runRainbowPalette();
break;
case 2:
runColorPalette();
break;
case 3:
runStars();
break;
case 4:
runVUmeter();
break;
case 5:
runDice();
break;
case 6:
runTetris();
break;
case 7:
runSnake();
break;
case 8:
runPong();
break;
case 9:
runBricks();
break;
}
} else {
//If we are here, no action was taken by the user, so we will move to the next selection automatically
curSelection++;
checkSelectionRange();
}
}
}
void checkSelectionRange(){
if (curSelection>MAXSELECTION){
curSelection = MINSELECTION;
} else if (curSelection<MINSELECTION){
curSelection = MAXSELECTION;
}
}