#include <Stepper.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
const int btn1 = 5;
const int btn2 = 4;
const int led1 = 3;
const int pot = A6;
int cnt = 0;
// Initialize the stepper library on pins 8 through 11:
const int motor_pin_1 = 8;
const int motor_pin_2 = 9;
const int motor_pin_3 = 10;
const int motor_pin_4 = 11;
int hf20 = 400;
Stepper myStepper(hf20, motor_pin_1, motor_pin_2, motor_pin_3, motor_pin_4);
void setup() {
myStepper.setSpeed(40);
lcd.init();
lcd.backlight();
pinMode(btn1, INPUT_PULLUP);
pinMode(btn2, INPUT_PULLUP);
pinMode(led1, OUTPUT);
lcd.setCursor(0,0);
lcd.print("Stepper OwO");
lcd.setCursor(0, 1);
lcd.print("ArkanAsadilHuda");
delay(1000);
lcd.clear();
}
void loop() {
hf20 = analogRead(pot);
if (digitalRead(btn1) == LOW) {
digitalWrite(led1, LOW);
myStepper.step(hf20);
cnt += hf20;
} else {
digitalWrite(led1, HIGH);
}
if (digitalRead(btn2) == LOW) {
if (cnt > 0) {
if (hf20 > cnt) {
lcd.print("Hold");
delay(1000);
lcd.clear();
} else {
digitalWrite(led1, LOW);
cnt -= hf20;
myStepper.step(-hf20);
}
} else {
lcd.setCursor(0, 1);
lcd.println("Minimum step!");
delay(1000);
lcd.clear();
}
}
lcd.setCursor(0, 0);
lcd.println("Step:");
lcd.setCursor(6, 0);
lcd.println(cnt);
lcd.setCursor(0, 1);
lcd.print("Sel: ");
lcd.println(hf20);
delay(100);
}