#include <LiquidCrystal_I2C.h>
#include <Stepper.h>

const int stepsPerRevolution = 1000;  // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

LiquidCrystal_I2C lcd(0x27, 20, 4);

void potong(){
  lcd.setCursor(2, 0);
  lcd.print("Memotong..");
  //turn clockwise
  myStepper.step(stepsPerRevolution);
  delay(1000);
  //anticlockwise
  myStepper.step(-stepsPerRevolution);
  lcd.clear();
  lcd.setCursor(2, 0);
  lcd.print("Selesai..");
}

void setup() {
  // kecepatan motor 60 rpm:
  myStepper.setSpeed(60);
  lcd.init();
  lcd.backlight();
  lcd.setCursor(2, 0);
  lcd.print("Kalibrasi");
  delay(1000);
  lcd.clear();
  lcd.setCursor(2, 0);
  lcd.print("Ready");
}

void loop() {
  int x = analogRead(A0);
  delay(10);
  
  if((analogRead(A0) - x) > 2){
    potong();
  }
  lcd.setCursor(2, 1);
  lcd.print(analogRead(A0));
}