So I am pretty new to coding with Arduino, and I created a program to run a bluetooth HC-05 CNC to specific points on a board. But, my code keeps throwing up an error. Here is my program...
#define EN 8
//Direction pin
#define X_DIR 5
#define Y_DIR 6
#define Z_DIR 7
//Step pin
#define X_STP 2
#define Y_STP 3
#define Z_STP 4
//DRV88252
int delayTime=500; //Delay between each pause (uS)
int stps=2000;// Steps to move
void step(boolean dir, byte dirPin, byte stepperPin, int steps)
{
digitalWrite(dirPin, dir);
delay(100);
for (int i = 0; i < steps; i++) {
digitalWrite(stepperPin, HIGH);
delayMicroseconds(delayTime);
digitalWrite(stepperPin, LOW);
delayMicroseconds(delayTime);
}
}
void setup()
{
pinMode(X_DIR, OUTPUT); pinMode(X_STP, OUTPUT);
pinMode(Y_DIR, OUTPUT); pinMode(Y_STP, OUTPUT);
pinMode(Z_DIR, OUTPUT); pinMode(Z_STP, OUTPUT);
pinMode(EN, OUTPUT);
digitalWrite(EN, LOW);
Serial.begin(9600); //Set the baud rate to your Bluetooth module.
}
void loop(){
while (Serial.available() > 0)
{
command = Serial.read();
Serial.println(command);
}
switch(command){
case '1':
step(false, X_DIR, X_STP, 2000);
step(true, Y_DIR, Y_STP, 0);
delay(10);
step(true,X_DIR,X_STP,3000);
step(true,Y_DIR, Y_STP, 0);
break;
case '2':
step(false, X_DIR, X_STP, 4000);
step(true, Y_DIR, Y_STP, 0);
delay(10);
step(true, X_DIR, X_STP, 4000);
step(true, Y_DIR, Y_STP, 0);
break;
case '3':
step(true, X_DIR, X_STP, 0);
step(false, Y_DIR, Y_STP, 2000);
delay(10);
step(true, X_DIR, X_STP, 0);
step(true, Y_DIR, Y_STP, 2000);
break;
case '4':
step(false, X_DIR, X_STP, 2000);
step(false, Y_DIR, Y_STP, 2000);
delay(10);
step(true, X_DIR, X_STP, 2000);
step(true, Y_DIR, Y_STP, 2000);
break;
case '5':
step(false, X_DIR, X_STP, 4000);
step(false, Y_DIR, Y_STP, 2000);
delay(10);
step(true, X_DIR, X_STP, 4000); //X2, Counterclockwise
step(true, Y_DIR, Y_STP, 2000);;
break;
}
}
}
The code keeps on throwing up the 'command' was not declared in this scope for, the line...
command = Serial.read();
Any tips that could help me solve this issue?