How to compare gathered barcode with determined code

Hi,
i'm using the code from this page: https://www.circuitsathome.com/mcu/connecting-barcode-scanner-arduino-usb-host-shield/[/url]

and I have troubles finding a solution. I just don't know how to compare the barcode I scanned with the barcode i want to determine.

I hope somebody can help me,
I'm thanking you in anticipation

If both barcodes are text and stored in a null terminated character array, you can use strcmp.

Please post your code here using code tags

Type [code]
Paste your code after that
Type [/code] after that

Don't mind the method wiegen()

#include <LiquidCrystal_I2C.h>
#include <avr/pgmspace.h> 
#include <Usb.h>
#include <hidboot.h>
#include <hiduniversal.h>
#include "HX711.h"
#include "UsbCore.h"




#define DISPLAY_WIDTH 16
#include <Keyboard.h> 

LiquidCrystal_I2C lcd(0x3F, 16 ,2); 
HX711 cell (A1, A0);


USB     Usb;
//USBHub     Hub(&Usb);
HIDUniversal Hid(&Usb);
long count = 0;
float val = 0;
float gewicht = 0;
char keys[14] = {'e',9,1,2,0,0,0,5,8,1,1,4,6,1};
char key;




 
class KbdRptParser : public KeyboardReportParser
{
        void PrintKey(uint8_t mod, uint8_t key);
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 schluessel)  
{
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;
      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
      lcd.setCursor( 0,1 );
    }
 
    key= char(schluessel);
    lcd.print( key );
    Serial.print(key);
     
  }
  ;
 
KbdRptParser Prs;

float wiegen(){
  count = count + 1;
  //val = ((count-1)/count) * val + (1/count)*cell.read();
  //val = 0.5 * val + 0.5* cell.read();
  val = cell.read();
  gewicht = ((val - 8584390 ) / (35846.0f / 75));
  //null 8584390
  return gewicht;
}
 
void setup()
{
    Serial.begin( 9600 );
    
 
    if (Usb.Init() == -1) {
        Serial.println("OSC did not start.");
    }
 
    delay( 200 );
 
    Hid.SetReportParser(0, &Prs);
    
    // set up the LCD's number of columns and rows: 
    lcd.begin();
    lcd.clear();
    lcd.noAutoscroll();
    lcd.print("Bereit:");
    delay( 200 );
    
    
}
 
void loop()
{
  Usb.Task();
 

 
}

Looks like it displays the key presses as they arrive but doesn't store them anywhere:

    key= char(schluessel);
    lcd.print( key );
    Serial.print(key);

I think you will need to store the characters in a buffer. Is there some marker that indicates the end of input from the scanner? If not, you may need a timeout to detect when the input is complete. Then you can compare the buffer against the desired data.

johnwasser:
Looks like it displays the key presses as they arrive but doesn't store them anywhere:

    key= char(schluessel);

lcd.print( key );
    Serial.print(key);




I think you will need to store the characters in a buffer. Is there some marker that indicates the end of input from the scanner? If not, you may need a timeout to detect when the input is complete. Then you can compare the buffer against the desired data.

Hi John, I am currently facing same issue with the OP. Appreciate your help to instruct me how to store the arrives data into buffer then compare with desired data. Thanks in advance!!!

fergieomni:
Appreciate your help to instruct me how to store the arrives data into buffer then compare with desired data. Thanks in advance!!!

Is there some marker character that indicates the end of input from the scanner?

fergieomni:
Hi John, I am currently facing same issue with the OP. Appreciate your help to instruct me how to store the arrives data into buffer then compare with desired data. Thanks in advance!!!

Change this

  Serial.print(key);

to

  Serial.println(key, HEX);

That will show you exactly what is received (in hexadecimal representation) so you can determine if there are markers (e.g. '\n' (0x0A) as an endmarker). See e.g. http://www.asciitable.com/ if you need help with the codes that you see.

You will need to read up on arrays to store the data; Serial Input Basics shows how it is done for serial communication but you can apply the principles to your scenario.

The compare can be done with e.g. strcmp() (text based) or memcmp (binary based).