const int enPin = 8; const int stepXPin = 2; //X.STEP const int dirXPin = 5; // X.DIR int stepPin = stepXPin; int dirPin = dirXPin; const int stepsPerRev = 200; int pulseWidthMicros = 100; // microseconds int millisBtwnSteps = 1000; const int buttonPin = 11; int buttonState = 0; void setup() { Serial.begin(9600); pinMode(enPin, OUTPUT); digitalWrite(enPin, LOW); pinMode(stepPin, OUTPUT); pinMode(dirPin, OUTPUT); Serial.println(F("CNC Shield Initialized")); pinMode(buttonPin, INPUT); } void loop() { buttonState = digitalRead(buttonPin); Serial.println(buttonState); if (buttonState == HIGH) { Serial.println(F("Running counter-clockwise")); //Blade cuts the paper digitalWrite(dirPin, LOW); //Changes the rotations direction // Makes 400 pulses for making two full cycle rotation for (int i = 0; i < stepsPerRev * 7; i++) { digitalWrite(stepPin, HIGH); delayMicroseconds(pulseWidthMicros); digitalWrite(stepPin, LOW); delayMicroseconds(millisBtwnSteps); } Serial.println("Running clockwise"); // Blade goes back to start point digitalWrite(dirPin, HIGH); // Enables the motor to move in a particular direction // Makes 200 pulses for making one full cycle rotation for (int i = 0; i < stepsPerRev * 7; i++) { digitalWrite(stepPin, HIGH); delayMicroseconds(pulseWidthMicros); digitalWrite(stepPin, LOW); delayMicroseconds(millisBtwnSteps); } } }