Components and supplies
Resistor 10k ohm
Arduino Micro
Breadboard (generic)
Project description
Code
Code
arduino
Note that some variables are in catalan. 'Boto' means 'Button', 'Fila' means 'Row', 'Columna' means 'Column', 'StatusAnterior' means 'LastStatus'
1#include "Keyboard.h" 2 3// constants won't change. They're used here to set pin numbers: 4const int button1Pin = 2; // the number of the pushbutton pin 5const int button2Pin = 3; // the number of the pushbutton pin 6const int button3Pin = 4; // the number of the pushbutton pin 7const int button4Pin = 5; // the number of the pushbutton pin 8const int button5Pin = 6; // the number of the pushbutton pin 9 10 11// variables will change: 12int button1State = 0; // variable for reading the pushbutton status 13int button2State = 0; 14int button3State = 0; 15int button4State = 0; 16int button5State = 0; 17 18int boto1status = 0; 19int boto2status = 0; 20int boto3status = 0; 21int boto4status = 0; 22int boto5status = 0; 23int boto1statusanterior = 0; 24int boto2statusanterior = 0; 25int boto3statusanterior = 0; 26int boto4statusanterior = 0; 27int boto5statusanterior = 0; 28 29int fila = 0; 30int columna = 0; 31 32 33void setup() { 34 Serial.begin(9600); 35 Keyboard.begin(); 36 // initialize the pushbutton pin as an input: 37 pinMode(button1Pin, INPUT); 38 pinMode(button2Pin, INPUT); 39 pinMode(button3Pin, INPUT); 40 pinMode(button4Pin, INPUT); 41 pinMode(button5Pin, INPUT); 42 43} 44 45void loop() { 46 47 48 // PULSACIO FÍSICA DE BOTONS ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 49 50 51 button1State = digitalRead(button1Pin); 52 button2State = digitalRead(button2Pin); 53 button3State = digitalRead(button3Pin); 54 button4State = digitalRead(button4Pin); 55 button5State = digitalRead(button5Pin); 56 57 boto1statusanterior = boto1status; 58 boto2statusanterior = boto2status; 59 boto3statusanterior = boto3status; 60 boto4statusanterior = boto4status; 61 boto5statusanterior = boto5status; 62 63 if (button1State == HIGH) { 64 boto1status = 1; 65 delay (50); 66 } else { 67 boto1status = 0; 68// delay (50); 69 } 70 if (button2State == HIGH) { 71 boto2status = 1; 72 delay (50); 73 } else { 74 boto2status = 0; 75// delay (50); 76 } 77 if (button3State == HIGH) { 78 boto3status = 1; 79 delay (50); 80 } else { 81 boto3status = 0; 82// delay (50); 83 } 84 if (button4State == HIGH) { 85 boto4status = 1; 86 delay (50); 87 } else { 88 boto4status = 0; 89// delay (50); 90 } 91 if (button5State == HIGH) { 92 boto5status = 1; 93 delay (50); 94 } else { 95 boto5status = 0; 96// delay (50); 97 } 98 99 100// ASSIGNAR FILES O COLUMNES SEGONS EL BOTÓ PULSAT ++++++++++++++++++++++++++++++++++++++++++++++ 101 102 if (boto1statusanterior != boto1status) { 103 if (boto1status == 0) { 104 if (fila == 0) { 105 fila = 1; 106 } else { 107 columna = 1; 108 } 109 } 110 } 111 if (boto2statusanterior != boto2status) { 112 if (boto2status == 0) { 113 if (fila == 0) { 114 fila = 2; 115 } else { 116 columna = 2; 117 } 118 } 119 } 120 if (boto3statusanterior != boto3status) { 121 if (boto3status == 0) { 122 if (fila == 0) { 123 fila = 3; 124 } else { 125 columna = 3; 126 } 127 } 128 } 129 if (boto4statusanterior != boto4status) { 130 if (boto4status == 0) { 131 if (fila == 0) { 132 fila = 4; 133 } else { 134 columna = 4; 135 } 136 } 137 } 138 if (boto5statusanterior != boto5status) { 139 if (boto5status == 0) { 140 if (fila == 0) { 141 fila = 5; 142 } else { 143 columna = 5; 144 } 145 } 146 } 147 148 149// ESCRIU SEGONS FILA I COLUMNA 150 151 if (fila != 0 && columna != 0) { 152 153 ////// VOCALS 154 155 if (fila == 1 && columna == 1) { 156 Serial.write("A"); 157 Keyboard.write('a'); 158 } 159 if (fila == 1 && columna == 2) { 160 Serial.write("E"); 161 Keyboard.write('e'); 162 } 163 if (fila == 1 && columna == 3) { 164 Serial.write("I"); 165 Keyboard.write('i'); 166 } 167 if (fila == 1 && columna == 4) { 168 Keyboard.write('o'); 169 Serial.write("O"); 170 } 171 if (fila == 1 && columna == 5) { 172 Keyboard.write('u'); 173 Serial.write("U"); 174 } 175 176 ////// CONSONANTS 1 177 178 if (fila == 2 && columna == 1) { 179 Serial.write("C"); 180 Keyboard.write('c'); 181 } 182 if (fila == 2 && columna == 2) { 183 Serial.write("D"); 184 Keyboard.write('d'); 185 } 186 if (fila == 2 && columna == 3) { 187 Serial.write("L"); 188 Keyboard.write('l'); 189 } 190 if (fila == 2 && columna == 4) { 191 Serial.write("N"); 192 Keyboard.write('n'); 193 } 194 if (fila == 2 && columna == 5) { 195 Serial.write("R"); 196 Keyboard.write('r'); 197 } 198 199 ////// CONSONANTS 2 200 201 if (fila == 3 && columna == 1) { 202 Serial.write("S"); 203 Keyboard.write('s'); 204 } 205 if (fila == 3 && columna == 2) { 206 Serial.write("T"); 207 Keyboard.write('t'); 208 } 209 if (fila == 3 && columna == 3) { 210 Serial.write("B"); 211 Keyboard.write('b'); 212 } 213 if (fila == 3 && columna == 4) { 214 Serial.write("F"); 215 Keyboard.write('f'); 216 } 217 if (fila == 3 && columna == 5) { 218 Serial.write("G"); 219 Keyboard.write('g'); 220 } 221 222 ////// CONSONANTS 3 223 224 if (fila == 4 && columna == 1) { 225 Serial.write("M"); 226 Keyboard.write('m'); 227 } 228 if (fila == 4 && columna == 2) { 229 Serial.write("P"); 230 Keyboard.write('p'); 231 } 232 if (fila == 4 && columna == 3) { 233 Serial.write("J"); 234 Keyboard.write('j'); 235 } 236 if (fila == 4 && columna == 4) { 237 Serial.write("X"); 238 Keyboard.write('x'); 239 } 240 if (fila == 4 && columna == 5) { 241 Serial.write("Z"); 242 Keyboard.write('z'); 243 } 244 245 fila = 0; 246 columna = 0; 247 } 248 if (fila == 5) { 249 Serial.println(); 250 Keyboard.write(10); 251 fila = 0; 252 columna = 0; 253 } 254 255 256}
Code
arduino
Note that some variables are in catalan. 'Boto' means 'Button', 'Fila' means 'Row', 'Columna' means 'Column', 'StatusAnterior' means 'LastStatus'
1#include "Keyboard.h" 2 3// constants won't change. They're used 4 here to set pin numbers: 5const int button1Pin = 2; // the number of the pushbutton 6 pin 7const int button2Pin = 3; // the number of the pushbutton pin 8const 9 int button3Pin = 4; // the number of the pushbutton pin 10const int button4Pin 11 = 5; // the number of the pushbutton pin 12const int button5Pin = 6; // 13 the number of the pushbutton pin 14 15 16// variables will change: 17int button1State 18 = 0; // variable for reading the pushbutton status 19int button2State = 20 0; 21int button3State = 0; 22int button4State = 0; 23int button5State = 0; 24 25int 26 boto1status = 0; 27int boto2status = 0; 28int boto3status = 0; 29int boto4status 30 = 0; 31int boto5status = 0; 32int boto1statusanterior = 0; 33int boto2statusanterior 34 = 0; 35int boto3statusanterior = 0; 36int boto4statusanterior = 0; 37int boto5statusanterior 38 = 0; 39 40int fila = 0; 41int columna = 0; 42 43 44void setup() { 45 Serial.begin(9600); 46 47 Keyboard.begin(); 48 // initialize the pushbutton pin as an input: 49 pinMode(button1Pin, 50 INPUT); 51 pinMode(button2Pin, INPUT); 52 pinMode(button3Pin, INPUT); 53 pinMode(button4Pin, 54 INPUT); 55 pinMode(button5Pin, INPUT); 56 57} 58 59void loop() { 60 61 62 63 // PULSACIO FÍSICA DE BOTONS ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 64 65 66 67 button1State = digitalRead(button1Pin); 68 button2State = digitalRead(button2Pin); 69 70 button3State = digitalRead(button3Pin); 71 button4State = digitalRead(button4Pin); 72 73 button5State = digitalRead(button5Pin); 74 75 boto1statusanterior = boto1status; 76 77 boto2statusanterior = boto2status; 78 boto3statusanterior = boto3status; 79 80 boto4statusanterior = boto4status; 81 boto5statusanterior = boto5status; 82 83 84 if (button1State == HIGH) { 85 boto1status = 1; 86 delay (50); 87 } 88 else { 89 boto1status = 0; 90// delay (50); 91 } 92 if (button2State 93 == HIGH) { 94 boto2status = 1; 95 delay (50); 96 } else { 97 boto2status 98 = 0; 99// delay (50); 100 } 101 if (button3State == HIGH) { 102 boto3status 103 = 1; 104 delay (50); 105 } else { 106 boto3status = 0; 107// delay (50); 108 109 } 110 if (button4State == HIGH) { 111 boto4status = 1; 112 delay (50); 113 114 } else { 115 boto4status = 0; 116// delay (50); 117 } 118 if (button5State 119 == HIGH) { 120 boto5status = 1; 121 delay (50); 122 } else { 123 boto5status 124 = 0; 125// delay (50); 126 } 127 128 129// ASSIGNAR FILES O COLUMNES SEGONS 130 EL BOTÓ PULSAT ++++++++++++++++++++++++++++++++++++++++++++++ 131 132 if (boto1statusanterior 133 != boto1status) { 134 if (boto1status == 0) { 135 if (fila == 0) { 136 fila 137 = 1; 138 } else { 139 columna = 1; 140 } 141 } 142 } 143 144 if (boto2statusanterior != boto2status) { 145 if (boto2status == 0) { 146 if 147 (fila == 0) { 148 fila = 2; 149 } else { 150 columna = 2; 151 152 } 153 } 154 } 155 if (boto3statusanterior != boto3status) { 156 if 157 (boto3status == 0) { 158 if (fila == 0) { 159 fila = 3; 160 } else 161 { 162 columna = 3; 163 } 164 } 165 } 166 if (boto4statusanterior 167 != boto4status) { 168 if (boto4status == 0) { 169 if (fila == 0) { 170 fila 171 = 4; 172 } else { 173 columna = 4; 174 } 175 } 176 } 177 178 if (boto5statusanterior != boto5status) { 179 if (boto5status == 0) { 180 if 181 (fila == 0) { 182 fila = 5; 183 } else { 184 columna = 5; 185 186 } 187 } 188 } 189 190 191// ESCRIU SEGONS FILA I COLUMNA 192 193 if 194 (fila != 0 && columna != 0) { 195 196 ////// VOCALS 197 198 if (fila 199 == 1 && columna == 1) { 200 Serial.write("A"); 201 Keyboard.write('a'); 202 203 } 204 if (fila == 1 && columna == 2) { 205 Serial.write("E"); 206 207 Keyboard.write('e'); 208 } 209 if (fila == 1 && columna == 3) 210 { 211 Serial.write("I"); 212 Keyboard.write('i'); 213 } 214 215 if (fila == 1 && columna == 4) { 216 Keyboard.write('o'); 217 Serial.write("O"); 218 219 } 220 if (fila == 1 && columna == 5) { 221 Keyboard.write('u'); 222 223 Serial.write("U"); 224 } 225 226 ////// CONSONANTS 1 227 228 229 if (fila == 2 && columna == 1) { 230 Serial.write("C"); 231 232 Keyboard.write('c'); 233 } 234 if (fila == 2 && columna == 2) 235 { 236 Serial.write("D"); 237 Keyboard.write('d'); 238 } 239 240 if (fila == 2 && columna == 3) { 241 Serial.write("L"); 242 Keyboard.write('l'); 243 244 } 245 if (fila == 2 && columna == 4) { 246 Serial.write("N"); 247 248 Keyboard.write('n'); 249 } 250 if (fila == 2 && columna == 5) 251 { 252 Serial.write("R"); 253 Keyboard.write('r'); 254 } 255 256 257 ////// CONSONANTS 2 258 259 if (fila == 3 && columna == 1) { 260 261 Serial.write("S"); 262 Keyboard.write('s'); 263 } 264 if 265 (fila == 3 && columna == 2) { 266 Serial.write("T"); 267 Keyboard.write('t'); 268 269 } 270 if (fila == 3 && columna == 3) { 271 Serial.write("B"); 272 273 Keyboard.write('b'); 274 } 275 if (fila == 3 && columna == 4) 276 { 277 Serial.write("F"); 278 Keyboard.write('f'); 279 } 280 281 if (fila == 3 && columna == 5) { 282 Serial.write("G"); 283 Keyboard.write('g'); 284 285 } 286 287 ////// CONSONANTS 3 288 289 if (fila 290 == 4 && columna == 1) { 291 Serial.write("M"); 292 Keyboard.write('m'); 293 294 } 295 if (fila == 4 && columna == 2) { 296 Serial.write("P"); 297 298 Keyboard.write('p'); 299 } 300 if (fila == 4 && columna == 3) 301 { 302 Serial.write("J"); 303 Keyboard.write('j'); 304 } 305 306 if (fila == 4 && columna == 4) { 307 Serial.write("X"); 308 Keyboard.write('x'); 309 310 } 311 if (fila == 4 && columna == 5) { 312 Serial.write("Z"); 313 314 Keyboard.write('z'); 315 } 316 317 fila = 0; 318 columna 319 = 0; 320 } 321 if (fila == 5) { 322 Serial.println(); 323 324 Keyboard.write(10); 325 fila = 0; 326 columna = 0; 327 } 328 329 330 331}
Downloadable files
Rough sketch
Rough sketch
Rough sketch
Rough sketch
Scheme
Considering my lack of experience in electronics, I'm sure there is some way to optimize the scheme. But this is the one that works well for me at the moment.
Scheme
Comments
Only logged in users can leave comments
gtentacle
0 Followers
•0 Projects
Table of contents
Intro
9
0