-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEarthSeed.ino
More file actions
193 lines (175 loc) · 3.64 KB
/
EarthSeed.ino
File metadata and controls
193 lines (175 loc) · 3.64 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
Borrows code from LiquidCrystal Library - Hello World
http://www.arduino.cc/en/Tutorial/LiquidCrystalHelloWorld
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int led1 = 6, led2 = 7, led3 = 8, led4 = 9, led5 = 10;
const int button = A6;
// Variables
bool pressed = false;
int mainNum = 0;
int menuNum = 0;
bool uranusProbed = false;
bool gameOver = false;
int probes = 10;
int switchToChoice()
{
//Serial.write(switchVal);
int switchVal = analogRead(button);
if(switchVal > 5 && switchVal < 11)
return 5;
else if(switchVal > 14 && switchVal < 21)
return 4;
else if(switchVal > 44 && switchVal < 50)
return 3;
else if(switchVal > 89 && switchVal < 95)
return 2;
else if(switchVal > 234 && switchVal < 241)
return 1;
return 0;
}
void setup() {
// set up LED pins
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
Serial.begin(9600);
generatePlanetStats();
}
void loop() {
//int switchVal = analogRead(A6);
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
//lcd.setCursor(0, 1);
//if(switchVal == 0)
// lcd.print("0 ");
//else
// lcd.print(switchVal);
//int choice = switchToChoice();
//makeChoice(choice);
//planetScan();
//mainMenu();
loadMenu();
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
if(analogRead(button) == 0)
pressed = false;
}
void mainMenu() {
String option = "";
switch(mainNum)
{
case 1:
option = "Probe Planet";
break;
case 2:
option = "Check Status";
break;
case 3:
option = "Land";
break;
case 4:
option = "Move On";
break;
default:
option = "Scan Planet";
break;
}
//Wipe away any characters left behind
for(int i=16-option.length(); i > 0; i--)
{
option += " ";
}
lcd.setCursor(0, 0);
lcd.print(option);
lcd.setCursor(0, 1);
lcd.print("< > Enter ");
//int switchVal = analogRead(button);
if(!pressed)
{
switch(switchToChoice())
{
case 1:
mainNum--;
if(mainNum < 0)
mainNum = 4;
pressed = true;
break;
case 2:
mainNum++;
if(mainNum > 4)
mainNum = 0;
pressed = true;
break;
case 3:
menuNum = mainNum+1;
pressed = true;
break;
default:
break;
}
}
}
void loadMenu()
{
switch(menuNum)
{
case 1:
planetScan();
break;
case 2:
probePlanet();
case 3:
shipStats();
break;
case 4:
endGame();
break;
case 5:
randomEvent();
break;
default:
if(!gameOver)
mainMenu();
break;
}
}
void probePlanet()
{
if(probes > 0)
{
uranusProbed = true;
probes--;
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("PROBE LAUNCHED");
lcd.setCursor(0,1);
lcd.print(" ");
delay(3000);
menuNum = 1;
}
else
{
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("NO MORE PROBES");
lcd.setCursor(0,1);
lcd.print(" ");
delay(3000);
menuNum = 1;
}
}