#include <HX711_ADC.h>
#include <EEPROM.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 16);
const int HX711_dout = 4; //mcu > HX711 dout pin
const int HX711_sck = 5; //mcu > HX711 sck pin
HX711_ADC LoadCell(HX711_dout, HX711_sck);
int tpin = 3;
const int calVal_eepromAdress = 0;
long t;
const int Up_buttonPin = 9; // the pin that the pushbutton is attached to
const int Down_buttonPin = 8;
float buttonPushCounter = 0; // counter for the number of button presses
float up_buttonState = 0; // current state of the up button
float up_lastButtonState = 0; // previous state of the up button
float down_buttonState = 0; // current state of the up button
float down_lastButtonState = 0; // previous state of the up button
bool bPress = false;
int R1 = 10;
int R2 = 11;
void setup() {
Serial.begin(57600);
delay(10);
Serial.println();
Serial.println("Starting...");
pinMode(tpin, INPUT_PULLUP);
pinMode(6, OUTPUT);
pinMode(12, OUTPUT);
pinMode( Up_buttonPin , INPUT_PULLUP);
pinMode( Down_buttonPin , INPUT_PULLUP);
pinMode(R1, OUTPUT);
pinMode(R2, OUTPUT);
lcd.init();
lcd.backlight();
lcd.setCursor(2, 0);
lcd.print("CV DENITECH");
lcd.setCursor(3, 1);
lcd.print("MACHINERY");
delay(3000);
lcd.clear();
LoadCell.begin(); // start connection to HX711
LoadCell.start(1000); // load cells gets 1000ms of time to stabilize
float calibrationValue; // calibration value (see example file "Calibration.ino")
calibrationValue = 0.0; // uncomment this if you want to set the calibration value in the sketch
}
void loop() {
static boolean newDataReady = 0;
const int serialPrintInterval = 0; //increase value to slow down serial print activity
// check for new data/start next conversion:
if (LoadCell.update()) newDataReady = true;
// get smoothed value from the dataset:
if (newDataReady)
{
if (millis() > t + serialPrintInterval) {
float i = LoadCell.getData();
Serial.print("Load_cell output val: ");
Serial.println(i);
newDataReady = 0;
t = millis();
lcd.setCursor(0, 0);
lcd.print("Tujuan :");
lcd.setCursor(9, 0);
lcd.print(buttonPushCounter);
lcd.setCursor(14, 0);
lcd.print("GM");
lcd.setCursor(0, 1);
lcd.print("Aktual :");
lcd.setCursor(9, 1);
lcd.print(i);
lcd.setCursor(14, 1);
lcd.print("GM");
}
}
checkUp();
checkDown();
if (digitalRead(tpin) == LOW) {
LoadCell.tareNoDelay();
}
// check if last tare operation is complete:
if (LoadCell.getTareStatus() == true) {
lcd.clear();
lcd.print("Tare complete");
delay(1000);
lcd.clear();
}
float i = LoadCell.getData();
float k = buttonPushCounter- i;
if (i <= buttonPushCounter)
{
digitalWrite (6, HIGH);
digitalWrite (10, LOW);
digitalWrite (12, LOW);
}
if (i >= buttonPushCounter)
{
digitalWrite (6, LOW);
digitalWrite (12, HIGH);
digitalWrite (10, HIGH);
}
if (i <= buttonPushCounter *0.9)
{
digitalWrite (11, LOW);
}
if (i >= buttonPushCounter *0.9)
{
digitalWrite (11, HIGH);
}
else
{
digitalWrite(12, LOW);
}
}
void checkUp()
{
up_buttonState = digitalRead(Up_buttonPin);
// compare the buttonState to its previous state
if (up_buttonState!= up_lastButtonState)
{
// if the state has changed, increment the counter
if (up_buttonState == LOW)
{
bPress = true;
// if the current state is HIGH then the button went from off to on:
buttonPushCounter = buttonPushCounter + 50;
}
}
// save the current state as the last state, for next time through the loop
up_lastButtonState = up_buttonState;
}
void checkDown()
{
down_buttonState = digitalRead(Down_buttonPin);
// compare the buttonState to its previous state
if (down_buttonState != down_lastButtonState)
{
// if the state has changed, increment the counter
if (down_buttonState == LOW)
{
bPress = true;
buttonPushCounter = buttonPushCounter - 50;
}
}
// save the current state as the last state, for next time through the loop
down_lastButtonState = down_buttonState;
}