Hello guys,
I want to create a custom panel for my online simulator using matrix keypad 4x3 and library USBKeyboard that can send key stroke to pc for simulate the normal usb keyboard.
my idea is the follow:
ARDUINO UNO board, connect the keypad with an IC PCF8574P( with address 0x20) and wire library for use only two wire, use the usb shield with 2 diode (zener 3,6v 0,5w) and three resistors.
I try to write a code for that project but don't work. but if i use only one code this work fine, in order if i simulate a USBkeyboard with one switch it works and if i use only the two wire keypad it works fine but if i combine both not working.
the code is the follow:
#include "UsbKeyboard.h"
#include <Wire.h>
#include <i2ckeypad.h>
#define ROWS 4
#define COLS 3
//matrix keypad Address
#define PCF8574_ADDR 0x20
//Object keypad
i2ckeypad kpd = i2ckeypad(PCF8574_ADDR, ROWS, COLS);
char key;
void setup()
{
// Disable timer0 since it can mess with the USB timing. Note that
// this means some functions such as delay() will no longer work.
TIMSK0&=!(1<<TOIE0);
// Clear interrupts while performing time-critical operations
cli();
// Force re-enumeration so the host will detect us
usbDeviceDisconnect();
delayMs(250);
usbDeviceConnect();
// Set interrupts again
sei();
Wire.begin(); //inizialize Wire library
kpd.init(); //inizialize object keypad
}
void loop()
{
UsbKeyboard.update();
key=kpd.get_key();
if (key != ' \0 ') {
UsbKeyboard.sendKeyStroke(KEY_H, MOD_SHIFT_LEFT);
UsbKeyboard.sendKeyStroke(KEY_E);
UsbKeyboard.sendKeyStroke(KEY_L);
UsbKeyboard.sendKeyStroke(KEY_L);
UsbKeyboard.sendKeyStroke(KEY_O);
UsbKeyboard.sendKeyStroke(KEY_SPACE);
UsbKeyboard.sendKeyStroke(KEY_W, MOD_SHIFT_LEFT);
UsbKeyboard.sendKeyStroke(KEY_O);
UsbKeyboard.sendKeyStroke(KEY_R);
UsbKeyboard.sendKeyStroke(KEY_L);
UsbKeyboard.sendKeyStroke(KEY_D);
UsbKeyboard.sendKeyStroke(KEY_ENTER);
}
}
/**
* Define our own delay function so that we don't have to rely on
* operation of timer0, the interrupt used by the internal delay()
*/
void delayMs(unsigned int ms)
{
for (int i = 0; i < ms; i++) {
delayMicroseconds(1000);
}
}
i don't have idea why isn't working, i spent three days but i don't understand why

i wait for you help me!
