Adding keyboard & pause in arduino wire cutter using stepper motor

Hello
I am new here so first Hello to all! :slight_smile:

As I mentioned I am new to arduino and don't have any clue to programming just basic knowledge of using it and uploading existing programs.
I want to make the project of wire cutting machine from following link

I have a small problem (big one for me) but I am sure that for some of you here it is a simple thing.

What I need is as follows:

  1. Is it possible to input the values using 4x3 matrix keypad as inputting various length with 2 button is very tough
    eg. 200mm x 4 nos, 800mm x 3 nos, 2000mm x 8nos, 3500mm x 5 nos

  2. How to insert wire sensor like optical sensor so as to be able to pause the running code in absence of wire & display message on display like "wire finish please insert wire"

Noe I did search the net and this forum but usually what I encountered is much complex tasks and/or missing one of the above.

If anybody knows of a way for me to get the things to do the above I would be more than great-full.

THANK YOU!!

  1. Is it possible to input the values using 4x3 matrix keypad

Of course it is.

  1. How to insert wire sensor like optical sensor so as to be able to pause the running code in absence of wire & display message on display like "wire finish please insert wire"

Grab your handy-dandy sensor catalog, and order a wire sensor. Connect it to the Arduino, and write the proper code to read the sensor.

What? There isn't a "wire sensor" in the index? Bummer. So, what ARE you going to use to sense the presence/absence of wire? Why is it even remotely difficult to read that sensor?

This is not a "write the code for me" forum. You study the examples, for the keypad, for instance, and figure out how they work, and incorporate the ideas into your program. If you get stuck, you'll have specific questions, which we can answer for you.

udaykumarpatil2008:
As I mentioned I am new to arduino and don't have any clue to programming just basic knowledge of using it and uploading existing programs.

Learn and understand the first five demos in IDE->file/examples/digital/. This will give you a base of knowledge to work from.

udaykumarpatil2008:

  1. Is it possible to input the values using 4x3 matrix keypad as inputting various length with 2 button is very tough
    eg. 200mm x 4 nos, 800mm x 3 nos, 2000mm x 8nos, 3500mm x 5 nos

There are numerous threads on this subject and there are libraries available in the playground if you don't want to build it from scratch. Use the search bar at the top of the page, there's a better than even chance what you want to do has already been done by someone.

udaykumarpatil2008:
2. How to insert wire sensor like optical sensor so as to be able to pause the running code in absence of wire & display message on display like "wire finish please insert wire"

What sort of sensor? As in so many cases the answer is "It depends." There are dozens, maybe more, varieties of 'optical sensors'. You'll have to search places like Mouser, Digi-key, etc. to find something you think will work.

udaykumarpatil2008:
Noe I did search the net and this forum but usually what I encountered is much complex tasks and/or missing one of the above.

This is where creativity enters. Once you understand how to do one thing you can incorporate it into the next thing, and so on. At your apparent level it is almost impossible to build this on the first try. Don't even approach it that way. Learn what the small pieces are and how they fit together. Baby steps. Then you combine the parts in various ways to make different things.

Thanks for the reply
I try to modify the code (just copy, paste &try to merge two code) but getting "error too many arguments to function ‚Äėvoid changeValue()‚Äô "

the code is as follows

//------------------------------- librarys ----------------------------------

#include <LiquidCrystal.h>
#include <Servo.h>
#include <Keypad.h>
 
//------------------------------- lcd ----------------------------------
const int rs = 11, en = 12, d4 = 2, d5 = 3, d6 = 4, d7 = 5;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
 
//------------------------------- stepper ----------------------------------
#define stepPin 7
#define dirPin 8
 
//------------------------------- servo ----------------------------------
Servo snippers;
#define servo 10
#define openAngle 180
#define closedAngle 0
 
//------------------------------- input ----------------------------------
 
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char key;
//define the cymbols on the buttons of the keypads
char keys[ROWS][COLS] = {
    {'1','2','3'},
    {'4','5','6'},
    {'7','8','9'},
    {'*','0','#'}
};
byte rowPins[ROWS] = {3, 2, 1, 0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); // Keypad Library definition

volatile int firstnumber=99;  // used to tell how many numbers were entered on keypad
volatile int secondnumber=99;
volatile int thirdnumber=99;
volatile int fourthnumber=99;

// Variables to hold length and quantity
int keyfullnumber=0;  // used to store the final length value
//------------------------------- user settings ----------------------------------
unsigned int wireLength = 0;
unsigned int wireQuantity = 0;
 
//------------------------------- system settings ----------------------------------
int state = 0;
int previousWireLength = 0;
int previousWireQuantity = 0;
float mmPerStep = 0.18096;
 
 
void setup() {
  Serial.begin(9600);
   
  lcd.begin(16, 2); //LCD columns and rows
 
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
  snippers.attach(servo); 
  snippers.write(openAngle);
   
  delay(1000);
}
void buttonWait(int buttonPin){
  int buttonState = 0;
  while(1){
    buttonState = digitalRead(buttonPin);
    if (buttonState == HIGH) {
      return;
    }
  }
}

void loop() {
  char keypressed = keypad.getKey();  // Get value of keypad button if pressed
  if (keypressed != NO_KEY){  // If keypad button pressed check which key it was
    switch (keypressed) {
      
      case '1':
        checknumber(1);
      break;
        
      case '2':
        checknumber(2);
      break;

      case '3':
        checknumber(3);
      break;

      case '4':
        checknumber(4);
      break;

      case '5':
        checknumber(5);
      break;

      case '6':
        checknumber(6);
      break;

      case '7':
        checknumber(7);
      break;

      case '8':
        checknumber(8);
      break;

      case '9':
        checknumber(9);
      break;

      case '0':
        checknumber(0);
      break;

      case '*':
        deletenumber();
      break;

      case '#':
        Next();
      break;
    }
  if (key == '#'){
    if(state == 5){
      state = 0;
    }
    else{
      state += 1;
    }
    delay(200);
    lcd.clear();
  }
  if (key == '*' && 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 Next() {  // Used to create a full number from entered numbers
    if (key == '*' && state > 0 && state < 4){
    state -=1;
    delay(200);
    lcd.clear();
   }
  } 
void checknumber(int x){
  if (firstnumber == 99) { // Check if this is the first number entered
    firstnumber=x;
    String displayvalue = String(firstnumber);  //  Transform int to a string for display
    
  } else {
    if (secondnumber == 99) {  // Check if it's the second number entered
      secondnumber=x;
      String displayvalue = (String(firstnumber) + String(secondnumber));

    } else {  // It must be the 3rd number entered
      thirdnumber=x;
      String displayvalue = (String(firstnumber) + String(secondnumber) + String(thirdnumber));

    }
  }
}
void resetnumbers() {  // Reset numbers for next entry
  firstnumber=99;
  secondnumber=99;
  thirdnumber=99;
} 

void deletenumber() {  // Used to backspace entered numbers
    if(state == 5){
      state = 0;
    }
    else{
      state += 1;
    }
    delay(200);
    lcd.clear();
  }

 
void homeScreen(){
  lcd.setCursor(0, 0);
  lcd.print("WIRE CUTTER");
  lcd.setCursor(0, 1);
  lcd.print("UDAY");
  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(600);
    snippers.write(openAngle);
    delay(600);
 
   
    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(0, 1);
  lcd.print("UDAY");
  lcd.setCursor(11, 1);
  lcd.print("NEXT>");
  delay(100);
}
 
void displayNavigation(){
  lcd.setCursor(0, 1);
  lcd.print("<BACK");
  lcd.setCursor(11, 1);
  lcd.print("NEXT>");
  delay(100);
}

void changeValue() {  // Used to create a full number from entered numbers

    if (thirdnumber == 99 && secondnumber == 99 && firstnumber != 99) {
      keyfullnumber=firstnumber;
    }
    
    if (secondnumber != 99 && thirdnumber == 99) {
      keyfullnumber=(firstnumber*10)+secondnumber;
    }
    
    if (thirdnumber != 99) {
      keyfullnumber=(firstnumber*100)+(secondnumber*10)+thirdnumber;
    }
    
    if (fourthnumber != 99) {
      keyfullnumber=(firstnumber*1000)+(secondnumber*100)+(thirdnumber*10)+fourthnumber;
    }
    
    return currentValue; // Reset numbers to get ready for new entry
  }

Please help on error & any other help in modifying code to simplify will be helpful.

The value that you pass to checknumber() is keypressed - ‚Äė0‚Äô. You REALLY could shorten that code.

  char keypressed = keypad.getKey();  // Get value of keypad button if pressed
  if (keypressed != NO_KEY){  // If keypad button pressed check which key it was
<snipped>
  if (key == '#'){
    if(state == 5){
      state = 0;

Why are you storing the value in keypressed, but testing key? You have not assigned a value to key.

  if (firstnumber == 99) { // Check if this is the first number entered
    firstnumber=x;
    String displayvalue = String(firstnumber);  //  Transform int to a string for display
   
  }

It is NOT necessary to convert an int to a String in order to be able to display the value. It is useless to do this when the String immediately goes out of scope.

void changeValue() {
<snipped>
    return currentValue; // Reset numbers to get ready for new entry

That comment is nonsense. It is NOT what the code does. The return statement is incorrect, because you have said that the function does not return a value.

  wireLength = changeValue(wireLength);

The function does not take a value. Why are you trying to pass it one?

Obviously, the function should return a value, but there is no reason, given the way that it is written, to have it take a value.

Thank you PaulS sir,
As i am new to programming, i partially understand your suggestions & tried to modify the code but still some errors are showing

//------------------------------- librarys ----------------------------------

#include <LiquidCrystal.h>
#include <Servo.h>
#include <Keypad.h>
 
//------------------------------- lcd ----------------------------------
const int rs = 11, en = 12, d4 = 2, d5 = 3, d6 = 4, d7 = 5;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
 
//------------------------------- stepper ----------------------------------
#define stepPin 7
#define dirPin 8
 
//------------------------------- servo ----------------------------------
Servo snippers;
#define servo 10
#define openAngle 180
#define closedAngle 0
 
//------------------------------- input ----------------------------------
 
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char key;
//define the cymbols on the buttons of the keypads
char keys[ROWS][COLS] = {
    {'1','2','3'},
    {'4','5','6'},
    {'7','8','9'},
    {'*','0','#'}
};
byte rowPins[ROWS] = {3, 2, 1, 0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); // Keypad Library definition

volatile int firstnumber=99;  // used to tell how many numbers were entered on keypad
volatile int secondnumber=99;
volatile int thirdnumber=99;
volatile int fourthnumber=99;

// Variables to hold length and quantity
int keyfullnumber=0;  // used to store the final length value
//------------------------------- user settings ----------------------------------
unsigned int wireLength = 0;
unsigned int wireQuantity = 0;
 
//------------------------------- system settings ----------------------------------
int state = 0;
int previousWireLength = 0;
int previousWireQuantity = 0;
float mmPerStep = 0.18096;
 
 
void setup() {
  Serial.begin(9600);
   
  lcd.begin(16, 2); //LCD columns and rows
 
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
  snippers.attach(servo); 
  snippers.write(openAngle);
   
  delay(1000);
}
void loop() {
  char keypressed = keypad.getKey();  // Get value of keypad button if pressed
  if (keypressed != NO_KEY){  // If keypad button pressed check which key it was
  if (key == '#'){
    if(state == 5){
      state = 0;
    }
    else{
      state += 1;
    }
    delay(200);
    lcd.clear();
  }
  if (key == '*' && 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("WIRE CUTTER");
  lcd.setCursor(0, 1);
  lcd.print("UDAY");
  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(600);
    snippers.write(openAngle);
    delay(600);
 
   
    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(0, 1);
  lcd.print("UDAY");
  lcd.setCursor(11, 1);
  lcd.print("NEXT>");
  delay(100);
}
 
void displayNavigation(){
  lcd.setCursor(0, 1);
  lcd.print("<BACK");
  lcd.setCursor(11, 1);
  lcd.print("NEXT>");
  delay(100);
}

void changeValue(int currentValue){  // Used to create a full number from entered numbers
    char keypressed = keypad.getKey();  // Get value of keypad button if pressed
    if (keypressed != NO_KEY){  // If keypad button pressed check which key it was
    keypressed = keypad.getKey();
    }
    return currentValue; // Reset numbers to get ready for new entry
}

I got the error
In function ‚Äėvoid chooseWireQuantity()‚Äô:

error: void value not ignored as it ought to be

wireQuantity = changeValue(wireQuantity);

Same error for ‚Äėvoid chooseWireLength()‚Äô:

I search the google for the error, but couldnt understand much. I updated the my latest versions of libraries.

Please help on error & any other help in modifying code to simplify will be helpful.
Thank you very much for being with me with patience.

wireQuantity = changeValue(wireQuantity);

If a function is defined 'void', that means it doesn't return a value.
It is pointless, then, to assign the value that it doesn't return to a variable.

please suggest the modification

Either change the function's return type (preferred) to reflect the type of the returned value, or use a global (don't do this)

I tried to modify the code & finally error is resolved & uploading of code to arduino uno completed & first screen appears

//------------------------------- librarys ----------------------------------

#include <LiquidCrystal.h>
#include <Servo.h>
#include <Keypad.h>
 
//------------------------------- lcd ----------------------------------
const int rs = 4, en = 5, d4 = 6, d5 = 7, d6 = 8, d7 = 9;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
 
//------------------------------- stepper ----------------------------------
#define stepPin 10
#define dirPin 11
 
//------------------------------- servo ----------------------------------
Servo snippers;
#define servo 12
#define openAngle 180
#define closedAngle 0
 
//------------------------------- input ----------------------------------
 
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char key;
//define the cymbols on the buttons of the keypads
char keys[ROWS][COLS] = {
    {'1','2','3'},
    {'4','5','6'},
    {'7','8','9'},
    {'*','0','#'}
};
byte rowPins[ROWS] = {14, 15, 16, 17}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {18, 19, 3}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); // Keypad Library definition

volatile int firstnumber=99;  // used to tell how many numbers were entered on keypad
volatile int secondnumber=99;
volatile int thirdnumber=99;
volatile int fourthnumber=99;

// Variables to hold length and quantity
int keyfullnumber=0;  // used to store the final length value
//------------------------------- user settings ----------------------------------
unsigned int wireLength = 0;
unsigned int wireQuantity = 0;
 
//------------------------------- system settings ----------------------------------
int state = 0;
int previousWireLength = 0;
int previousWireQuantity = 0;
float mmPerStep = 0.18096;
 
 
void setup() {
  Serial.begin(9600);
   
  lcd.begin(16, 2); //LCD columns and rows
 
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
  snippers.attach(servo); 
  snippers.write(openAngle);
   
  delay(1000);
}
void loop() {
  char keypressed = kpd.getKey();  // Get value of keypad button if pressed
  if (keypressed != NO_KEY){  // If keypad button pressed check which key it was
  if (key == '#'){
    if(state == 5){
      state = 0;
    }
    else{
      state += 1;
    }
    delay(200);
    lcd.clear();
  }
  if (key == '*' && 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("WIRE CUTTER");
  lcd.setCursor(0, 1);
  lcd.print("UDAY");
  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();
}

int changeValue(int currentValue){  // Used to create a full number from entered numbers
    char keypressed = kpd.getKey();  // Get value of kpd button if pressed
    if (keypressed != NO_KEY){  // If keypad button pressed check which key it was
    keypressed = kpd.getKey();
    }
    return currentValue; // Reset numbers to get ready for new entry
}

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(600);
    snippers.write(openAngle);
    delay(600);
 
   
    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(0, 1);
  lcd.print("UDAY");
  lcd.setCursor(11, 1);
  lcd.print("NEXT>");
  delay(100);
}
 
void displayNavigation(){
  lcd.setCursor(0, 1);
  lcd.print("<BACK");
  lcd.setCursor(11, 1);
  lcd.print("NEXT>");
  delay(100);
}

The problem is after booting of uno
it should change state with button press ‚Äė#‚Äô but no effect of any button press.

for connection checking of circuit working only i tried to upload the sample codes
with modification & same are working.

for testing i just connected keypad & 16 x 2 lcd to uno
Please suggest.

Add some debug prints and find out what is going on.

The problem is after booting of uno
it should change state with button press '#' but no effect of any button press.

Why do you have so much code to deal with key presses, when you don't even know if the keypad is wired correctly?

Why do you have so much code to deal with key presses

I really don't know how to shorten the code. please help me to do this

when you don't even know if the keypad is wired correctly?

keypad & 16 x 2 lcd is configured & working properly for another code.

I don't know why the # key is not changing the state.

Please help

I don't know why the # key is not changing the state.

And you don't have any proof that pressing the # key is even recognized, let alone that the getKey() function returns the expected value.

We can NOT help you until you prove that the keypad is wired correctly (not using any pins used for some other purpose) and that the array passed to makeKeymap() is used correctly.

And you don’t have any proof that pressing the # key is even recognized, let alone that the getKey() function returns the expected value.

thanks I got the mistake, hence i started from the scratch & wrote the code again (just copy paste & some modifications)

code attached

but unfortunately im getting some errors as

error: void value not ignored as it ought to be

wireLength = calculatevalue(keyfullnumber);

&

error: void value not ignored as it ought to be

wireQuantity = calculatevalue(keyfullnumber);

please help on error also please help if any suggestion for modification in code

automatic_wire_cutter_my_program.ino (8.65 KB)

A function defined "void" does not return a value, so can't assign the value it doesn't return to anything

where the mistake is weather in
void chooseWireLength()
OR
void calculatevalue(int keyfullnumber)

where the mistake is

Why do you expect us to guess? The compiler told you EXACTLY what line number the error occurred on. You elected to post only a portion of the error message, so don't expect us to tell you which line number the error is on.

Hello,
I successfuuly completed the modification in the code & now same is working properly.
now I want to add wire sensor in the code so that if wire is not present &/or finished in between code it should pause the code until the wire is inserted & button is pressed.my working void code is given below.

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(600);
    snippers.write(openAngle);
    delay(600);
 
   
    lcd.setCursor(0, 1);
 
    unsigned long timeRemaining = ((millis() - timeForOneCycle)*(wireQuantity - (i+1)))/1000;
    lcd.print((String)timeRemaining + "s    ");
   
  }
  wireLength = 0;
  wireQuantity = 0;
  state = 5;
}

I have tried to write the code using ‚Äėif‚Äô as below
int stepsToTake = (int)wireLength/mmPerStep;
for(int i = 0; i < wireQuantity; i++){
if (buttonState == LOW){…
}

I also tried with while function instead of if.

but it skips to next state & did nothing in currently cutting mode.
Please help how can it be done.

now I want to add wire sensor

Do you have some kind of sensor that tells you that there is, or is not, a wire somewhere?

I have tried to write the code using ‚Äėif‚Äô as below
int stepsToTake = (int)wireLength/mmPerStep;
for(int i = 0; i < wireQuantity; i++){
if (buttonState == LOW){…
}

But you forgot to read the state of button, so you don’t know whether it is buttoned or not.