need some help stop button

I am make a speed controller for a engraver I have the program running but can work out how to include a stop button all the other functions working like ccw-cw, speed change on a pot.

this is the code I am working with

//
#include <LiquidCrystal.h>

const int enablePin = 9;
const int in1Pin = 8;
const int in2Pin = 10;
const int switchPin = 7;
const int potPin = 0;
const int onoff = 11;

 int Stop ;
//int motorEnabled ;
//int previousonoff;
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 6, 5, 4, 3, 2);

void setup()
{
  lcd.begin(16, 2);
  // initialize the serial communications:
  Serial.begin (9600);

  lcd.print("RPM -"); 

  pinMode(in1Pin, OUTPUT);
  pinMode(in2Pin, OUTPUT);
  pinMode(enablePin, OUTPUT);
  pinMode(switchPin, INPUT_PULLUP);
  pinMode(onoff, INPUT_PULLUP);
}
void loop(){
  
  int speed = analogRead(potPin) / 4;
  boolean reverse = digitalRead(switchPin);
  boolean stop = digitalRead(onoff);
  setMotor(speed, reverse);
  
  //if(onoff != previousonoff) {
    //if(onoff == LOW) {
// if the switch is high, motor will turn on one direction:
  
  if (digitalRead(switchPin) == HIGH) {
    digitalWrite(in1Pin, HIGH);   // set pin 2 on L293D low
    digitalWrite(in2Pin, HIGH);  // set pin 7 on L293D high
  }
  // if the switch is low, motor will turn in the opposite direction:
  //else {
   // digitalWrite(in1Pin, HIGH);  // set pin 2 on L293D high
    //digitalWrite(in2Pin, LOW);   // set pin 7 on L293D low
   
    
}

void setMotor(int speed, boolean reverse)
{
{
  analogWrite(enablePin, speed);
  digitalWrite(in1Pin, ! reverse);
  digitalWrite(in2Pin, reverse);
  
  //digitalWrite(onoff, stop);

  //set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(6, 0);
  lcd.print(speed);
  lcd.setCursor(0, 1);
  lcd.print(reverse);
  lcd.print("= CCW=1 or CW=0 ");
}

help please

I can't follow your code. You seem to have stuff to make the motor move in loop() and in setMotor().

Also, I have no idea what would be needed to stop the motor.

Is the stop button a momentary switch or a toggle switch?

If it is a momentary switch what do you expect to happen when you release it?

In general I would have a boolean variable to record the state of the stop switch and I would write my motor code so it wouldn't do anything if that variable is (say) HIGH.

...R

its a toggle switch that I will be using i would like to have so it only turns motor off.
its easy enough to run a switch on the enable line.
I just would rather do it with software so I can print to screen if it is off or on

Something like this pseudo code. The first line doesn't have to be next to the other lines

stopSetting = digitalRead(stopSwitchPin);

if (stopSetting == LOW) {
   digitalWrite(motorEnablePin, LOW);  // assuming LOW causes it to stop
   Serial.println("Stop Switch set");
}
else {
   digitalWrite(motorEnablePin, HIGH)
}

...R

will try that thanks