Hello everyone i'm a new user for arduino
I'm building a F-16 cockpit simulator but i have a problem
I have an Arduino Uno and i changed its hex codes to emulate HID Keyboard just like that:
Now i have keyboard but i have to use toggle switches instead of buttons
I need to have one keyboard char at a time
Like semi automatic guns instead of full auto
Here is my test circuit
And here's the code
/* Arduino USB Keyboard HID demo
* Cut/Copy/Paste Keys
*/
#define KEY_LEFT_CTRL 0x01
#define KEY_LEFT_SHIFT 0x02
#define KEY_RIGHT_CTRL 0x10
#define KEY_RIGHT_SHIFT 0x20
uint8_t buf[8] = {
0 }; /* Keyboard report buffer */
#define PIN_C 5
#define PIN_X 6
#define PIN_V 7
int state = 1;
void setup()
{
Serial.begin(9600);
pinMode(PIN_C, INPUT_PULLUP);
pinMode(PIN_X, INPUT_PULLUP);
pinMode(PIN_V, INPUT_PULLUP);
// Enable internal pull-ups
}
void loop()
{
int sensorVal = digitalRead(5);
state = digitalRead(PIN_X);
if (state != 1) {
buf[0] = 0;
buf[2] = 27; // Letter X
Serial.write(buf, 8); // Ssend keypress
releaseKey();
} else {
delay(5);
}
state = digitalRead(PIN_C);
if (state != 1) {
buf[0] = 0;
buf[2] = 6; // Letter C
Serial.write(buf, 8); // Send keypress
releaseKey();
} else {
delay(5);
}
state = digitalRead(PIN_V);
if (state != 1) {
buf[0] = 0;
buf[2] = 25; // Letter V
Serial.write(buf, 8); // Send keypress
releaseKey();
} else {
delay(5);
}
}
void releaseKey()
{
buf[0] = 0;
buf[2] = 0;
Serial.write(buf, 8); // Release key
delay(500);
}
Can you solve my problem? Thanks
Additional: Here is the keyboard codes:
http://scriptel.com/KeyboardEmulationAPI/JavaScript/tutorial-Keyboards.html