Hi
I beginner for Arduino i study with google and youtube and
I follow this example of barcode scanner
with my Arduino Uno and show it in 162 lcd LiquidCrystal
then I want to input value from key pad 44
to to show input in second line then I write code
#include <Keypad.h>
#include <hid.h> //Add to Oleg Mazurov code to Bar Code Scanner
#include <hiduniversal.h> //Add to Oleg Mazurov code to Bar Code Scanner
#include <usbhub.h>
#include <LiquidCrystal_I2C.h>
#include <avr/pgmspace.h>
//#include <avrpins.h> //I disable this line because it is already included with Usb.h
//#include <max3421e.h> // I disable this line because it is already included with Usb.h
//#include <usbhost.h> // I disable this line because it is already included with Usb.h
//#include <usb_ch9.h> // I disable this line because it is already included with Usb.h
#include <Usb.h>
#include <usbhub.h>
#include <avr/pgmspace.h>
//#include <address.h> // I disable this line because it is already included with Usb.h
#include <hidboot.h>
#include <Wire.h>
//#include <printhex.h> // I disable this line because it is already included with Usb.h
//#include <message.h> // I disable this line because it is already included with Usb.h
//#include <hexdump.h> // I disable this line because it is already included with Usb.h
//#include <parsetools.h> // I disable this line because it is already included with Usb.h
#define DISPLAY_WIDTH 16
// initialize the LCD library with the numbers of the interface pins
LiquidCrystal_I2C lcd(0x27, 16, 2);
const byte ROWS = 4; // Four rows
const byte COLS = 4; // columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = { 9,8,7,6 };
byte colPins[COLS] = { 5,4,3,2, };
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
USB Usb;
USBHub Hub(&Usb); //I enable this line
HIDUniversal Hid(&Usb); //Add this line so that the barcode scanner will be recognized, I use "Hid" below
HIDBoot<HID_PROTOCOL_KEYBOARD> Keyboard(&Usb);
class KbdRptParser : public KeyboardReportParser
{
void PrintKey(uint8_t mod, uint8_t key); // Add this line to print character in ASCII
protected:
virtual void OnKeyDown (uint8_t mod, uint8_t key);
virtual void OnKeyPressed(uint8_t key);
};
void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
{
uint8_t c = OemToAscii(mod, key);
if (c)
OnKeyPressed(c);
}
/* what to do when symbol arrives */
void KbdRptParser::OnKeyPressed(uint8_t key)
{
static uint32_t next_time = 0; //watchdog
static uint8_t current_cursor = 0; //tracks current cursor position
if( millis() > next_time ) {
lcd.clear();
current_cursor = 0;
delay( 5 ); //LCD-specific
lcd.setCursor( 0,0 );
}//if( millis() > next_time ...
next_time = millis() + 200; //reset watchdog
//if( current_cursor++ == ( DISPLAY_WIDTH + 1 )) { //switch to second line if cursor outside the screen I disable this to show input from keypad
//lcd.setCursor( 0,1 );
//}
Serial.print( (char)key ); //Add char to print correct number in ASCII
lcd.print( (char)key ); //Add char to print correct number in ASCII
};
KbdRptParser Prs;
void setup()
{
Serial.begin( 115200 );
keypad.addEventListener(keypadEvent);
lcd.begin();
lcd.setCursor(0, 0);
if (Usb.Init() == -1) {
Serial.println("OSC did not start.");
}
delay( 200 );
Hid.SetReportParser(0, (HIDReportParser*)&Prs); //Here I change "Keyboard" for "Hid"
// set up the LCD's number of columns and rows:
lcd.print("Ready");
delay( 200 );
}
void loop()
{
Usb.Task();
keypad.getKey();
}
void keypadEvent(KeypadEvent eKey){
lcd.setCursor(0,1);
Serial.print(eKey);
lcd.print(eKey);
}
but the output that show in lcd screen in line 2 is A
and i don't know where is come from
and i can't press the keypad to show too
Is there any things i missed
pleas help me
i try every way i can but it's not work
ps. sorry for my weak Eng gramma ![]()