-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKey6.ino
217 lines (182 loc) · 5.62 KB
/
Key6.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/*
El movimiento del mouse siempre es relativo, no olviden eso, ademas los pasos depende de la resolución a la que
tengan configurado su mouse en el sistema perativo.
Cuando es programa esté completado si quieren usar la configuración de teclaod en español se debe usar la libreria
"Keyboard_ES"
WARNING: When you use the Mouse.move() command, the Arduino takes over your
mouse! Make sure you have control before you use the mouse commands.
Programa para usar un teclado de 2 filas por 3 columnas, en total 6 teclas,
Con este programa se recrea el funcionamiento de un teclaod normal, pero bajando mucho la complejidad.
Programa realizado por : Rafael Zapata Grau
e-mail: razapata@gmail.com
Comandos del mouse:
Mouse.begin()
Mouse.click()
Mouse.end()
Mouse.move()
Mouse.press()
Mouse.release()
Mouse.isPressed()
Comandos del teclado:
Keyboard.begin()
Keyboard.end()
Keyboard.press()
Keyboard.print()
Keyboard.println()
Keyboard.release()
Keyboard.releaseAll()
Keyboard.write()
*/
#include "Keyboard.h"
#include "Mouse.h"
// set pin numbers for the five buttons:
const int Rows[] = {2 , 3};
const int Cols[] = {4, 5, 6};
const int RowsCounter = 2;
const int ColsCounter = 3;
/* Información para hacer tarea periodica */
unsigned long startMillis; //Variable Global
unsigned long currentMillis;
const unsigned long periodo = 150; //Peridodo de ejecución en milisegundos
int thisPin;
int i;
int j;
void setup() { // Inicializando los Digital Input y las digital Output
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
for (thisPin = 0; thisPin < RowsCounter; thisPin++)
{
pinMode(Rows[thisPin], OUTPUT);
}
for (thisPin = 0; thisPin < ColsCounter; thisPin++)
{
pinMode(Cols[thisPin], INPUT);
}
//Serial.begin(9600); //No necesito el puerto serial por ahora
// initialize mouse control:
delay(10000); // Espero 10 segundos para que el driver del Teclado haga efecto.
Mouse.begin();
delay(250);
Keyboard.begin();
delay(250);
startMillis = millis(); //inicializa el tiempo, millis() devuelve el valor del tiempo de ejecución del programa en milisengundos.
digitalWrite(13, HIGH);
}
void loop() {
currentMillis = millis();
for(i = 0; i < RowsCounter; i++)
{
digitalWrite(Rows[i],LOW);
delay(20);
}
if ( (currentMillis - startMillis >= periodo) || (currentMillis - startMillis < 0) )
{
// codigo a ejecutar
for(i = 0; i < RowsCounter; i++)
{
digitalWrite(Rows[i],HIGH);
delay(20);
for(j = 0; j < ColsCounter; j++ )
{
if( digitalRead(Cols[j])== HIGH )
{
if(i == 0)
{
switch (j){
case 0:
boton1();
break;
case 1:
boton2();
break;
case 2:
boton3();
break;
}
}
if(i == 1)
{
switch (j){
case 0:
boton4();
break;
case 1:
boton5();
break;
case 2:
boton6();
break;
}
}
}
digitalWrite(Rows[i],LOW);
delay(10); // delay por seguridad
}
}
startMillis = currentMillis; // condición para evaluar el siguiente vez
//Se enciende Led para verificar que se ejecutó por lo menos una vez el código
//digitalWrite(13, HIGH);
delay(1);
}
}
void boton1()
{
Keyboard.println("Test Boton 1. Sí presiono Enter. ññ");
delay(50);
}
void boton2()
{
Keyboard.println("Test Boton 1. Sí presiono Enter. ññ");
delay(50);
}
void boton3()
{
Keyboard.press('x');
delay(50);
Mouse.press();
delay(50);
//Keyboard.release();
Keyboard.release('x');
delay(50);
Keyboard.press('z');
delay(50);
//Mouse.press();
delay(50);
Keyboard.release('z');
delay(50);
Keyboard.press('c');
delay(50);
//Mouse.press();
delay(50);
Keyboard.release('c');
delay(50);
Mouse.release();
delay(50);
Keyboard.press('x');
delay(50);
Keyboard.release('x');
delay(50);
}
void boton4()
{
Keyboard.print("Test Boton 4. No presiono Enter. ññ");
delay(50);
}
void boton5()
{
Keyboard.println("Test Boton 5. Sí presiono Enter. ññ");
delay(50);
Keyboard.println("Test Boton 5. á, é, í, ó, ú, ñ, ~");
delay(50);
}
void boton6()
{
Mouse.move(500, 0);
delay(1000);
Mouse.move(5000, 0);
delay(1000);
Mouse.move(10000, 0);
delay(1000);
Mouse.move(20000, 0);
delay(1000);
}