Paso 3: código
#include < core.h >#include < stdio.h >
#include < string.h >
#include < linux/input.h >
#include < fcntl.h >
#include < sys/time.h >
#include < unistd.h >
int InData1 = 0;
int InData2 = 0;
int InData3 = 0;
int InData4 = 0;
int InData5 = 0;
int TouchSensitivity = 800;
int num = 38;
void simulate_key (int fd, int kval)
{
struct input_event evento;
gettimeofday (y event.time, 0);
Event.Type = EV_KEY;
Event.Value = 1;
Event.Code = kval;
escribir (fd y evento, sizeof(event));
Event.Type = EV_SYN;
Event.Value = 0;
Event.Code = SYN_REPORT;
escribir (fd y evento, sizeof(event));
memset (& evento, 0, sizeof(event));
gettimeofday (y event.time, 0);
Event.Type = EV_KEY;
Event.Value = 0;
Event.Code = kval;
escribir (fd y evento, sizeof(event));
Event.Type = EV_SYN;
Event.Value = 0;
Event.Code = SYN_REPORT;
escribir (fd y evento, sizeof(event));
}
void simulate_mouse (int fd, int rel_x, int rel_y)
{
struct input_event evento;
gettimeofday (y event.time, 0);
Event.Type = EV_REL;
Event.Value = rel_x;
Event.Code = REL_X;
escribir (fd y evento, sizeof(event));
Event.Type = EV_REL;
Event.Value = rel_y;
Event.Code = REL_Y;
escribir (fd y evento, sizeof(event));
Event.Type = EV_SYN;
Event.Value = 0;
Event.Code = SYN_REPORT;
escribir (fd y evento, sizeof(event));
}
void setup()
{
para (int i = 6; i < = 12; i ++)
{
pinMode (i, salida);
}
}
void loop()
{
int fd_mouse;
int fd_kbd;
int i = 0;
fd_kbd = open ("/ dev/input/event1", O_RDWR);
Si (fd_kbd < = 0)
{
printf ("no puede abrir teclado entrada archivo\n");
while(1);
}
while(1)
{
InData1 = analogRead(A1);
InData2 = analogRead(A2);
InData3 = analogRead(A3);
InData4 = analogRead(A4);
InData5 = analogRead(A5);
Si (InData1 < = num)
{
digitalWrite (7, alto);
simulate_key (fd_kbd, KEY_S);
Delay(500);
InData1 = 2000;
InData2 = 2000;
InData3 = 2000;
InData4 = 2000;
InData5 = 2000;
}
Else digitalWrite (7, bajo);
Si (InData2 < = TouchSensitivity)
{
digitalWrite (8, HIGH);
simulate_key (fd_kbd, KEY_D);
Delay(500);
InData1 = 2000;
InData2 = 2000;
InData3 = 2000;
InData4 = 2000;
InData5 = 2000;
}
Else digitalWrite (8, bajo);
Si (InData3 < = TouchSensitivity)
{
digitalWrite (9, alto);
simulate_key (fd_kbd, KEY_F);
Delay(500);
InData1 = 2000;
InData2 = 2000;
InData3 = 2000;
InData4 = 2000;
InData5 = 2000;
}
Else digitalWrite (9, bajo);
Si (InData4 < = TouchSensitivity)
{
digitalWrite (10, HIGH);
simulate_key (fd_kbd, KEY_G);
Delay(500);
InData1 = 2000;
InData2 = 2000;
InData3 = 2000;
InData4 = 2000;
InData5 = 2000;
}
Else digitalWrite (10, bajo);
Si (InData5 < = TouchSensitivity)
{
digitalWrite (11, alto);
simulate_key (fd_kbd, KEY_H);
Delay(500);
InData1 = 2000;
InData2 = 2000;
InData3 = 2000;
InData4 = 2000;
InData5 = 2000;
}
Else digitalWrite (11, bajo);
Delay(100);
}
}
El código puede descargarse desde aquí (https://github.com/pcduino/scratch4pcduino_project/blob/master/TestCode.ino).