-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmemory_games.ino
77 lines (71 loc) · 1.4 KB
/
memory_games.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
#include "list.hpp"
LinkedList<int> ia;
bool buttonState0 = false;
bool buttonState1 = false;
bool buttonState2 = false;
bool buttonState3 = false;
void setup()
{
// pinMode(A0, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
pinMode(A4, INPUT);
pinMode(A5, INPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
randomSeed(analogRead(0));
}
void wait_button(void)
{
while (true) {
if (digitalRead(A2) == HIGH) {
buttonState0 = true;
return;
}
else
buttonState0 = false;
if (digitalRead(A3) == HIGH) {
buttonState1 = true;
return;
}
else
buttonState1 = false;
if (digitalRead(A4) == HIGH) {
buttonState2 = true;
return;
}
else
buttonState2 = false;
if (digitalRead(A5) == HIGH) {
buttonState3 = true;
return;
}
else
buttonState3 = false;
}
}
bool check_input(int pin)
{
if (pin == 10 && buttonState0 == true)
return true;
if (pin == 11 && buttonState1 == true)
return true;
if (pin == 12 && buttonState2 == true)
return true;
if (pin == 13 && buttonState3 == true)
return true;
return false;
}
void loop()
{
ia.Append(random(10, 14));
if(ia.moveToStart())
do{
wait_button();
int button_ia = ia.getCurrent();
if (check_input(button_ia) == false)
puts("Cool");
}while(ia.next());
}