Devices & Components
Arduino Uno Rev3
1N4007 – High Voltage, High Current Rated Diode
Resistor 10k ohm
Tactile Switch, Top Actuated
Breadboard (generic)
Jumper wires (generic)
Project description
Code
2x2x2 Cubed Inputs
arduino
Gives you the ability to get more buttons than inputs
1/* 2 Created by: 3 4 Amos Parmenter 5 July 20th 2019 6 7 8 The code is setup with the idea that you can 9 fit more buttons onto the Arduino 10 that inputs allow. 11 The code uses the idea of assigning vector 12 identity 13 to a node that will be unique when compared to other nodes. 14 15 This version 16 is setup as 2x2x2 cube and can fit 8 buttons 17 into 6 analog slots. It is scalable 18 in cubed 19 form (3x3x3.(mega), 4x4x4.(mega) , 5x5x5.(mega maxed inputs)). 20 21 The 5x5x5 uses 15 analog pins but in return gives you 125 buttons. 22 23 There 24 are mathematical complications to this code that 25 I haven’t fully worked out.To 26 be sure you don’t get false 27 positives for buttons you can only turn on one 28 button at a time. 29 In most cases you can have two buttons on at once but not 30 31 every two combinations are allowed. 32 Any three combinations will always give 33 you false positives. 34 The simulations I wired in 123D Circuits with the 2x2x2 35 36 cubed wiring and is running this version of code. 37 38*/ 39 40 41const int 42 x0 = 0; // input pins 43const int x1 = 1; // input pins 44const int y0 = 2; // 45 input pins 46const int y1 = 3; // input pins 47const int z0 = 4; // input pins 48const 49 int z1 = 5; // input pins 50 51int x_0; // nodes 52int x_1; // nodes 53int y_0; 54 // nodes 55int y_1; // nodes 56int z_0; // nodes 57int z_1; // nodes 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 /* This section allows you to check 133 the active button by entering 134 the number 135 1 into the Serail monitor 136 */ 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
Downloadable files
2x2x2 Cubed Inputs
the complete 2x2x2 circuit wiring
2x2x2 Cubed Inputs

2x2x2 Cubed Inputs
the complete 2x2x2 circuit wiring
2x2x2 Cubed Inputs

Comments
Only logged in users can leave comments