I am new here and I am building some project to build third world communities to help with project to cut wire at certain length from YouTube
Here is the link https://www.youtube.com/watch?v=_dAJtTnHLYg
I would like to have some expertise advice to/or modify the code only to move servo motor to max speed and steeper motor to synchronizing with it
Everything s are working well but the servo motor is so slow
How can I speed the servo motor?
Can someone please modify the code to speed up and repost here because I am not a programmer or coder.
I really appreciate your time and help to help
/*
Youtube : https://www.youtube.com/c/403ERRORVN
Fanpage : https://www.facebook.com/403ERRORVN
Blog : https://thichchetaotv.blogspot.com/
Date : 19/08/2022
Update : 19/08/2022
*/
//------------------------------- librarys ----------------------------------
#include <LiquidCrystal.h>
#include <Servo.h>
//------------------------------- lcd ----------------------------------
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
//------------------------------- stepper ----------------------------------
#define stepPin 8
#define dirPin 9
//------------------------------- servo ----------------------------------
Servo snippers;
#define servo 10
#define openAngle 0 // Góc ban đầu của Servo
#define closedAngle 140 // Góc khi Servo cắt dây
//------------------------------- input ----------------------------------
#define leftButton A0
#define rightButton A3
#define upButton A2
#define downButton A1
//------------------------------- user settings ----------------------------------
unsigned int wireLength = 0;
unsigned int wireQuantity = 0;
//------------------------------- system settings ----------------------------------
int state = 0;
int incrementSpeed = 1;
int previousWireLength = 0;
int previousWireQuantity = 0;
float mmPerStep = 0.1681;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2); //LCD columns and rows
pinMode(upButton, INPUT_PULLUP);
pinMode(downButton, INPUT_PULLUP);
pinMode(leftButton, INPUT_PULLUP);
pinMode(rightButton, INPUT_PULLUP);
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
snippers.attach(servo);
snippers.write(openAngle);
delay(1000);
lcd.setCursor(0, 0);
lcd.setCursor(0, 1);
delay(2000);
}
void loop() {
if (!digitalRead(rightButton)){
if(state == 5){
state = 0;
}
else{
state += 1;
}
delay(200);
lcd.clear();
}
if (!digitalRead(leftButton) && state > 0 && state < 4){
state -=1;
delay(200);
lcd.clear();
}
switch (state){
case 0:
homeScreen();
break;
case 1:
chooseWireLength();
break;
case 2:
chooseWireQuantity();
break;
case 3:
confirm();
break;
case 4:
currentlyCutting();
break;
case 5:
finishedCutting();
break;
}
}
void homeScreen(){
lcd.setCursor(0, 0);
lcd.print("ABB WIRE CUTTER");
lcd.setCursor(11, 1);
lcd.print("NEXT>");
delay(100);
}
void chooseWireLength(){
wireLength = changeValue(wireLength);
//clear LCD if required
if(previousWireLength != wireLength){
lcd.clear();
previousWireLength = wireLength;
}
//Display information on LCD
lcd.setCursor(0, 0);
lcd.print("LENGTH:" + (String)wireLength + "mm");
displayNavigation();
}
void chooseWireQuantity(){
wireQuantity = changeValue(wireQuantity);
//clear LCD if required
if(previousWireQuantity != wireQuantity){
lcd.clear();
previousWireQuantity = wireQuantity;
}
//Display information on LCD
lcd.setCursor(0, 0);
lcd.print("QUANTITY:" + (String)wireQuantity);
displayNavigation();
}
void confirm(){
lcd.setCursor(0, 0);
lcd.print((String)wireLength + "mm x " + (String)wireQuantity + "pcs");
lcd.setCursor(0, 1);
lcd.print("<BACK");
lcd.setCursor(10, 1);
lcd.print("START>");
delay(100);
}
void currentlyCutting(){
lcd.setCursor(0, 0);
lcd.print((String)0 + "/" + (String)wireQuantity);
lcd.setCursor(0, 1);
lcd.print("???s");
int stepsToTake = (int)wireLength/mmPerStep;
for(int i = 0; i < wireQuantity; i++){
unsigned long timeForOneCycle = millis();
digitalWrite(dirPin,HIGH);
for(int x = 0; x < stepsToTake; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(500);
digitalWrite(stepPin,LOW);
delayMicroseconds(500);
}
lcd.setCursor(0, 0);
lcd.print((String)(i+1) + "/" + (String)wireQuantity);
snippers.write(closedAngle);
delay(1000);
snippers.write(openAngle);
delay(1000);
lcd.setCursor(0, 1);
unsigned long timeRemaining = ((millis() - timeForOneCycle)*(wireQuantity - (i+1)))/1000;
lcd.print((String)timeRemaining + "s ");
}
wireLength = 0;
wireQuantity = 0;
state = 5;
}
void finishedCutting(){
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("CUTTING COMPLETE");
lcd.setCursor(11, 1);
lcd.print("NEXT>");
delay(100);
}
int changeValue(int currentValue){
if (!digitalRead(upButton)) {
currentValue += incrementSpeed;
incrementSpeed ++;
}
if (!digitalRead(downButton)) {
if(currentValue - incrementSpeed >= 0){
currentValue -= incrementSpeed;
incrementSpeed ++;
}
else{
currentValue = 0;
}
}
if (digitalRead(downButton) && digitalRead(upButton)){
incrementSpeed = 1;
}
return currentValue;
}
void displayNavigation(){
lcd.setCursor(0, 1);
lcd.print("<BACK");
lcd.setCursor(11, 1);
lcd.print("NEXT>");
delay(100);
}
`
`> type or paste code here`
`