can any tell me what i am doing wrong here i think it should work now i have downloaded the library
Accelstepper.h
it has me baffled just learning to code
albert
const int buttonpin = 12;// jog button clockwise
const int buttonpin1 = 11;// jog button counter clockwise
int buttonState = 0;
#include <AccelStepper.h>
// define the stepper and the pins it will use
AccelStepper stepper1(1, 9, 8); // 9= step ,8= direction
AccelStepper stepper2(1, 9, 8); // 9= step ,8= direction
// define our 3 input buttons
#define LEFT_PIN 4
#define STOP_PIN 3
#define RIGHT_PIN 2
// Define our analog pot input pin
#define SPEED_PIN 0
// Define our maximum and minimum speed in steps per second (scale pot to these)
#define MAX_SPEED 5000
#define MIN_SPEED .01
void setup() {
// The only Accelstepper value we have to set here is the max speed, which is higher than you will ever go
stepper1.setMaxSpeed(10000.0)
// set up the three button inputs, with pullups
pinMode(LEFT_PIN, INPUT_PULLUP);
pinMode(STOP_PIN, INPUT_PULLUP);
pinMode(RIGHT_PIN, INPUT_PULLUP);
pinMode(buttonPin,INPUT);
pinMode(buttonPin1,INPUT);
}
void loop() {
buttonState = digitalRead(buttonPin);
static float current_speed = 0.0; // holds current motor speed in steps/second
static int analog_read_counter = 1000; //counts down to 0 to fire analog read
static char sign = 0; // holds -1, 1 or 0 to tirn motor on/off and control direction
static int analog_value = 0;
// if a switch is pushed down (low), set the sign value appropriately
if (digitalRead(LEFT_PIN) == 0) {
sign = 1;
}
else if (digitalRead(RIGHT_PIN) == 0) {
sign = 1;
}
else if (digitalRead(STOP_PIN) == 0) {
sign = 0
}
// we only want to read the pot every so often (because it takes to long time we dont
// want to do it every time trough main loop).
if (analog_read_counter > 0) {
analog_read_counter--:
}
else {
analog_read_counter = 6000;
// now read the pot (from 0 to 1023)
analog_value = anologRead(SPEED_PIN);
// give the stepper a chance to step if it needs to
stepper1.runSpeed();
// and scale the pots value from min to max speed
current_speed = sign * ((analog_value/1023.0) * (MAX_SPEED - MIN_SPEED)) + MIN_SPEED:
// UPDATE THE STEPPER TO RUN AT THIS NEW SPEED
stepper1.setSpeed(current_speed);
}
stepper1.runSpeed();
// jog button clockwise
if (digitalRead(buttonPin) ==HIGH){
current_speed = ((analog_value/1023.0) * (MAX_SPEED - MIN_SPEED)) + MIN_SPEED:
stepper1.setSpeed(-current_speed);
stepper1.runSpeed));
}
// jog button conter clockwise
if (digitalRead(buttonPin1) ==HIGH){
current_speed = ((analog_value/1023.0) * (MAX_SPEED - MIN_SPEED)) + MIN_SPEED:
stepper1.setSpeed(-current_speed);
stepper1.runSpeed));
}
}