1
39
40
41const int
42 x0 = 0;
43const int x1 = 1;
44const int y0 = 2;
45 input pins
46const int y1 = 3;
47const int z0 = 4;
48const
49 int z1 = 5;
50
51int x_0;
52int x_1;
53int y_0;
54
55int y_1;
56int z_0;
57int z_1;
58
59bool
60 btn0 = false;
61bool btn1 = false;
62bool btn2 = false;
63bool btn3 = false;
64bool
65 btn4 = false;
66bool btn5 = false;
67bool btn6 = false;
68bool btn7 = false;
69
70bool
71 vectorX = false;
72bool vectorY = false;
73bool vectorZ = false;
74
75bool btnBoolMatrix[]
76 = {btn0, btn1, btn2, btn3,
77 btn4, btn5, btn6, btn7
78
79 };
80
81int analogList[8][3] = {
82 {x0, y0, z0},
83
84 {x1, y0, z0},
85 {x0, y1, z0},
86 {x1, y1, z0},
87
88 {x0,
89 y0, z1},
90 {x1, y0, z1},
91 {x0, y1, z1},
92 {x1, y1, z1}
93};
94
95int
96 btnMatrix[8][3] = {
97 {x_0, y_0, z_0},
98 {x_1, y_0, z_0},
99 {x_0, y_1,
100 z_0},
101 {x_1, y_1, z_0},
102
103 {x_0, y_0, z_1},
104 {x_1,
105 y_0, z_1},
106 {x_0, y_1, z_1},
107 {x_1, y_1, z_1}
108};
109
110bool vectorXYZ
111 [3] {vectorX, vectorY, vectorZ};
112
113
114void setup()
115{
116 Serial.begin(9600);
117
118
119 pinMode(x0, INPUT);
120 pinMode(x1, INPUT);
121 pinMode(y0, INPUT);
122 pinMode(y1,
123 INPUT);
124 pinMode(z0, INPUT);
125 pinMode(z1, INPUT);
126
127}
128
129void loop()
130 {
131
132
137
138 while (Serial.available()
139 < 0);
140 int options = Serial.read() - '0';
141 if (options == 1) {
142
143 checkBtnList();
144
145 }
146
147}
148
149
150
151
152
153void checkBtnList() {
154
155 for (int i =
156 0; i < 8; i++) {
157
158 for (int i = 0; i < 3; i++) {
159 vectorXYZ[i]
160 = false;
161 }
162
163 for (int j = 0; j < 3; j++) {
164
165 btnMatrix[i][j]
166 = analogRead(analogList[i][j]);
167
168
169
170 if (btnMatrix[i][j] > 250 )
171 {
172 vectorXYZ[j] = true;
173 } else {
174 vectorXYZ[j] = false;
175
176 }
177
178 if (j == 2) {
179 if (vectorXYZ[0] == true && vectorXYZ[1]
180 == true && vectorXYZ[2] == true) {
181 btnBoolMatrix[i] = true;
182 }
183 else {
184 btnBoolMatrix[i] = false;
185 }
186 }
187
188 }
189
190 }
191
192 for (int s = 0; s < 7; s++) {
193 Serial.print(btnBoolMatrix[s]);
194
195 Serial.print(" ");
196 }
197 Serial.println(btnBoolMatrix[7]);
198
199}
200
201
202
203