0

I have arduino uno+usb shield+barcode sacnner+RF24 for transmitter and arduino uno+RF24 for receiver. i want to send scanner data to receiver. This is my code

//**********************************NRF*********************************//
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(6, 7); // CE, CSN
const byte address[6] = "999aa9";

//**********************************NRF*********************************//

//*************************USB BARCODE SCANNER**************************//
#include <usbhid.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 <avr/pgmspace.h>
#include <Usb.h>
#include <usbhub.h>
#include <avr/pgmspace.h>
#include <hidboot.h>
USB Usb;
HIDUniversal Hid(&Usb); //Add this line so that the barcode scanner will be recognized, I use "Hid" below
String inString = "";
String text = inString;
//*************************USB BARCODE SCANNER**************************//

//*************************USB BARCODE SCANNER**************************//
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);

}
//*************************USB BARCODE SCANNER**************************//
/* what to do when symbol arrives */
void KbdRptParser::OnKeyPressed(uint8_t key)
{

  if (key != 19) {
    inString += (char)key;

    //Serial.print((char)key);
    //delay(500);
  }
  else {
     //*****MENAMPILKAN PADA SERIAL PRINT*****//
    Serial.println(inString);
    inString = "";
    //Serial.println((char)0x0D);
     //*****MENAMPILKAN PADA SERIAL PRINT*****//


    //*****MENGIRIM KE TRANSMITTER******//



     //*****MENGIRIM KE TRANSMITTER******//

  }
    };
//******************//    
KbdRptParser Prs;
//******************// 

void setup()
{
  //****USB BARCODE****//
  Serial.begin(9600);
  if (Usb.Init() == -1) Serial.println("OSC did not start.");
  else
    Serial.println("BARCODE READY!");
  Serial.println((char)0x0D);
  Hid.SetReportParser(0, (HIDReportParser*)&Prs); //Change "Keyboard" for "Hid"
  //****USB BARCODE
//radio.write(&inString, sizeof(inString));
  //****NRF SETUP****//
   radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_HIGH);
  //radio.setDataRate(RF24_250KBPS);
  radio.stopListening();

   //****NRF SETUP****//

}



void loop()
{



 // delay(1000);
  unsigned long T1 = millis();
  Usb.Task();
}

The problem is, when i put the radio.Write in void KbdRptParser::OnKeyPressed(uint8_t key) the scanner is lagging, please tell me where i can put the radio.write. thank you

  • please format your code using the {} button .... also, please ask a question .... there is nothing to be answered when there is no question – jsotola Jul 26 at 2:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.