Hi Arduino community,
I’m working on the sketch posted below. I used the following integers and I was hoping that the integer GoSteps would return a value that i can use to drive a stepper motor a certain amount of steps.
int NumStepsC
int NumStepsN
int GoSteps = NumStepsN+(-NumStepsC);
As you can see ,in the printscreen from the serial monitor, this is not working. It would be much appreciated if someone could point out what i’m doing wrong.
// parts of this sketch are from this tutorial: Arduino Stepper Motor Tutorial! Widget46
//https://www.youtube.com/watch?v=KbDPgxHpgAA&t=186s
// thanks NYC CNC
#define PUSH_PIN1 2 // pin 2 connected to push button1
#define PUSH_PIN2 3 // pin 3 connected to push button2
#define PUSH_PIN3 4 // pin 4 connected to push button3
#define PUSH_PIN4 5 // pin 5 connected to push button4
#define STEP_PIN 11 // pin 11 connected to step pin easydriver
#define DIR_PIN 12 // pin 12 connected to dir pin easydriver
#define SLEEP_PIN 13 // pin 13 connected to sleep pin easydriver
#define MS1_PIN 14 // pin 14 connected to MS1 pin easydriver
#define MS2_PIN 15 // pin 15 connected to MS2 pin easydriver
int Distance = 0; // how far we've traveled
int Speed = 500; // control how fast to ''step'' the motor
int ButtonState1 = 0; // stores status of button1
int ButtonState2 = 0; // stores status of button2
int ButtonState3 = 0; // stores status of button3
int ButtonState4 = 0; // stores status of button4
int OnOrOffState1 = 0; // should the motor be running or should it be turened off
int NumStepsC = 1000; // position the stepper is currently at
int NumStepsN = 1000; // position the stepper needs to go
int GoSteps = NumStepsN+(-NumStepsC); ///CURRENt postion + (-NEW postion)
void setup() {
Serial.begin(9600);
pinMode(SLEEP_PIN,OUTPUT);
pinMode(DIR_PIN,OUTPUT);
pinMode(STEP_PIN,OUTPUT);
pinMode(MS1_PIN, OUTPUT);
pinMode(MS2_PIN,OUTPUT);
pinMode(PUSH_PIN1,INPUT_PULLUP); // push botton1
pinMode(PUSH_PIN2,INPUT_PULLUP); // push botton2
pinMode(PUSH_PIN3,INPUT_PULLUP); // push botton3
pinMode(PUSH_PIN4,INPUT_PULLUP); // push botton4
digitalWrite(DIR_PIN,LOW); // set motor to clockwise direction
digitalWrite(STEP_PIN,LOW); // dont let the stepper motor rotate
digitalWrite(MS1_PIN,HIGH); // LOW LOW = full stepp HIGH LOW = half stepp LOW HIGH = quarter step HIGH HIGH = eight step
digitalWrite(MS2_PIN, HIGH);
digitalWrite(SLEEP_PIN, HIGH); // Wake up EasyDriver
delay(5); // Wait for EasyDriver wake up
}
void loop() {
ButtonState1 = digitalRead(PUSH_PIN1);
if (ButtonState1 == LOW){ //LOW means that the button has been pushed
NumStepsN = 1000;
}
ButtonState2 = digitalRead(PUSH_PIN2);
if (ButtonState2 == LOW){ //LOW means that the button has been pushed
NumStepsN = 2000; // set NumSteps to 1000 > puts the valve in position 1
}
ButtonState3 = digitalRead(PUSH_PIN3);
if (ButtonState3 == LOW){ //LOW means that the button has been pushed
NumStepsN = 3000; // set NumSteps to 1000 > puts the valve in position 1
}
ButtonState4 = digitalRead(PUSH_PIN4);
if (ButtonState4 == LOW){ //LOW means that the button has been pushed
NumStepsN = 4000; // set NumSteps to 1000 > puts the valve in position 1
}
Serial.println();
Serial.print("NumStepsN");
Serial.print(" ");
Serial.print(NumStepsN);
delay(0);
Serial.println();
Serial.print("NumStepsC");
Serial.print(" ");
Serial.print(NumStepsC);
delay(0);
Serial.println();
Serial.print("GoSteps");
Serial.print(" ");
Serial.print(GoSteps);
delay(0);
Serial.println();
Serial.print("OnOrOffState1");
Serial.print(" ");
Serial.print(OnOrOffState1);
delay(1000);
}
thanks,
Martijn
