#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RotaryEncoder.h>
#include <Servo.h>
#include "HX711.h"
LiquidCrystal_I2C lcd(0x27, 20, 4); // Adresa LCD displeje a jeho rozlišení
RotaryEncoder encoder(8, 9); // Pin pro DT na 8, pin pro CLK na 9
Servo servoMotor;
int encoderButtonPin = 5; // Pin pro tlačítko enkodéru
int servoPin = 10; // Pin pro servomotor
int hx711_dt_pin = 6; // Pin DT pro váhu HX711
int hx711_sck_pin = 7; // Pin SCK pro váhu HX711
int targetWeight = 0; // Deklarácia premennej targetWeight
void setup() {
lcd.begin(20, 4); // Oprava: Pridané parametre pre počet stĺpcov a riadkov
lcd.backlight();
servoMotor.attach(servoPin);
pinMode(encoderButtonPin, INPUT_PULLUP); // Tlačidlo enkodéru s pull-up rezistorom
// Oprava: Odstránenie volania encoder.setup(), nie je potrebné pre RotaryEncoder knižnicu
pinMode(hx711_dt_pin, OUTPUT);
pinMode(hx711_sck_pin, OUTPUT);
}
void loop() {
int encoderValue = encoder.read(); // Oprava: Použitie read() namiesto readEncoder()
float currentWeight = measureWeight();
lcd.setCursor(0, 0);
lcd.print("Weight: ");
lcd.print(currentWeight);
lcd.print(" g ");
lcd.setCursor(0, 1);
lcd.print("Target: ");
lcd.print(targetWeight);
lcd.print(" g ");
if (digitalRead(encoderButtonPin) == HIGH) {
targetWeight = encoderValue;
delay(500);
}
if (currentWeight >= targetWeight) {
servoMotor.write(90);
} else {
servoMotor.write(0);
}
}
float measureWeight() {
// Tu pridaj kód na meranie váhy pomocou HX711
return 0.0; // Dummy return, nahraďte vlastným kódom pre meranie váhy
}