-
Notifications
You must be signed in to change notification settings - Fork 0
/
button.ino
85 lines (80 loc) · 2.36 KB
/
button.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
#include "Dot.h"
bool buttonFlag = false;
void buttonA (Dot (*arrays)[COL]) {
if (buttonIsON(BUTTON_A)) {
Serial.println("a");
int selectedRow = findSelectedCoordinate(arrays, ROW);
int selectedCol = findSelectedCoordinate(arrays, COL);
int movedRow = selectedRow;
int movedCol = selectedCol;
switch (getMode()) {
case 1://上
if (selectedRow!=0) movedRow--;
arrays[selectedRow][selectedCol].setSelect();
arrays[movedRow][selectedCol].setSelect();
break;
case 2://下
if (selectedRow!=ROW-1) movedRow++;
arrays[selectedRow][selectedCol].setSelect();
arrays[movedRow][selectedCol].setSelect();
break;
case 3://左
if (selectedCol!=COL-1) movedCol++;
arrays[selectedRow][selectedCol].setSelect();
arrays[selectedRow][movedCol].setSelect();
break;
case 4://右
if (selectedCol!=0) movedCol--;
arrays[selectedRow][selectedCol].setSelect();
arrays[selectedRow][movedCol].setSelect();
break;
}
delay(40);
// for (int i=0; i<ROW; i++) {
// for (int j=0; j<COL; j++) {
// if (field[i][j].getIsSelected()){
// Serial.print(field[i][j].getRow());
// Serial.print(" ");
// Serial.println(field[i][j].getCol());
// }
// }
// }
printField(field);
}
}
void buttonB (Dot (*arrays)[COL]) {
if (buttonIsON(BUTTON_B)) {
Serial.println("b");
if(!isInitedField) initField(arrays);
int selectedRow = findSelectedCoordinate(arrays, ROW);
int selectedCol = findSelectedCoordinate(arrays, COL);
isGameOver = arrays[selectedRow][selectedCol].dig();
delay(70);
printField(field);
}
}
void buttonC (Dot (*arrays)[COL]) {
if (buttonIsON(BUTTON_C)) {
Serial.println("c");
int selectedRow = findSelectedCoordinate(arrays, ROW);
int selectedCol = findSelectedCoordinate(arrays, COL);
arrays[selectedRow][selectedCol].setFlag();
delay(30);
printField(field);
}
}
bool buttonIsON (uint8_t button) {
//delay(50);
if (digitalRead(button)==LOW && !buttonFlag) {
buttonFlag = true;
sound(button);
return 1;
}
else if (digitalRead(button)==LOW && buttonFlag) {
return 0;
}
else {
buttonFlag = false;
return 0;
}
}