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