#include <AccelStepper.h>
// Define stepper motor connections and motor interface type. Motor interface type must be set to 1 when using a driver:
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1
// Create a new instance of the AccelStepper class:
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
int customDelay,customDelayMapped;
void setup()
{
//Serial.begin(9600);
// Set the maximum speed in steps per second:
stepper.setMaxSpeed(1300);
}
void loop()
{
// Set the speed in steps per second:
customDelayMapped = speedUp();
stepper.setSpeed(customDelayMapped);
//Serial.println(customDelayMapped);
// Step the motor with a constant speed as set by setSpeed():
stepper.runSpeed();
}
int speedUp() {
int customDelay = analogRead(A0); // Reads the potentiometer
int newCustom = map(customDelay, 0, 1023, 0,1200); // Convrests the read values of the potentiometer from 0 to 1023 into desireded delay values (300 to 4000)
return newCustom;
}
/* program pake lcd namun gagal di rpmnya
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <AccelStepper.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Define stepper motor connections and motor interface type. Motor interface type must be set to 1 when using a driver:
#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1
// Create a new instance of the AccelStepper class:
AccelStepper stepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
int customDelay,customDelayMapped;
LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
Serial.begin(9600);
// Set the maximum speed in steps per second:
stepper.setMaxSpeed(1300);
lcd.init(); // initialize the lcd
// Print a message to the LCD. Kolom 0-15 (16 kolom) & baris 0-1 (2 baris)
lcd.backlight();
lcd.setCursor(1,0);
lcd.print("Feeder Machine");
lcd.setCursor(0,1);
lcd.print("Rpm:");
}
void loop()
{
// Set the speed in steps per second:
customDelayMapped = speedUp();
stepper.setSpeed(customDelayMapped);
Serial.println(customDelayMapped);
lcd.setCursor(5,1);
lcd.print(customDelayMapped);
// Step the motor with a constant speed as set by setSpeed():
stepper.runSpeed();
}
int speedUp() {
int customDelay = analogRead(A0); // Reads the potentiometer
int newCustom = map(customDelay, 0, 1023, 0,1200); // Convrests the read values of the potentiometer from 0 to 1023 into desireded delay values (300 to 4000)
return newCustom;
} */