Hello guys , new to coding and i am currently using an arduino mega and a cnc shield v3
currently when i run this snip of code it returns an error
Xlimit not defined in scope
i understand this variable is local in CNC_setup()
is their any way to go around making it a global variable
void CNC_setup() {
// defines pins numbers
const int stepX = 2;
const int dirX = 5;
const int stepY = 3;
const int dirY = 6;
const int stepZ = 4;
const int dirZ = 7;
const int enPin = 8;
const int Xlimit = 9 ;
const int Ylimit = 10;
const int Zlimit = 11;
pinMode(stepX, OUTPUT);
pinMode(dirX, OUTPUT);
pinMode(stepY, OUTPUT);
pinMode(dirY, OUTPUT);
pinMode(stepZ, OUTPUT);
pinMode(dirZ, OUTPUT);
pinMode(enPin, OUTPUT);
digitalWrite(enPin, LOW);
digitalWrite(dirX, HIGH);
digitalWrite(dirY, LOW);
digitalWrite(dirZ, HIGH);
pinMode(Xlimit, INPUT);
pinMode(Ylimit, INPUT);
pinMode(Zlimit, INPUT);
}
void Calibrate() {
CNC_setup();
if (Xlimit == LOW) {
digitalWrite(stepX, HIGH);
if (Xlimit == HIGH) {
digitalWrite(stepX, LOW);
}
}
if (Ylimit == LOW) {
digitalWrite(stepY, HIGH);
if (Ylimit == HIGH) {
digitalWrite(stepY, LOW);
}
}
if (Zlimit == LOW) {
digitalWrite(stepZ, HIGH);
if (Zlimit == HIGH) {
digitalWrite(stepZ, LOW);
}
}
}
void Motor_Movment(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);
}
}