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();
}