Skip to content

Instantly share code, notes, and snippets.

@jce90

jce90/alarm Secret

Last active January 25, 2021 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jce90/abc2d33035fd39c2098892dc0a29583b to your computer and use it in GitHub Desktop.
Save jce90/abc2d33035fd39c2098892dc0a29583b to your computer and use it in GitHub Desktop.
#include <AccelStepper.h>
#include <Servo.h>
// for the Arduino Uno + CNC shield V3 + A4988 + FL42STH47-1684A
#define STEPPER_ENABLE_PIN 8
#define STEPPER_STEP_PIN 2
#define STEPPER_DIR_PIN 5
Servo servo01;
int pos = 0;
#define limitSwitch 10
AccelStepper STEPPER(1, STEPPER_STEP_PIN, STEPPER_DIR_PIN);
void setup()
{
Serial.begin(9600); // Start the Serial monitor with speed of 9600 Bauds
pinMode(limitSwitch, INPUT_PULLUP);
servo01.attach(11);
servo01.write(0);
STEPPER.setEnablePin(STEPPER_ENABLE_PIN);
STEPPER.setPinsInverted(false, false, true);
STEPPER.setMaxSpeed(3000);
//MOTOR_Z.setSpeed(100);
STEPPER.enableOutputs();
while (digitalRead(limitSwitch) != 0) { // Make the Stepper move CCW until the switch is activated
STEPPER.setSpeed(800); // Set the position to move to
STEPPER.runSpeed(); // Start moving the stepper
}
delay(500);
STEPPER.setCurrentPosition(0);
while (STEPPER.currentPosition() != -1200) {
STEPPER.setSpeed(-1000);
STEPPER.run();
}
STEPPER.setCurrentPosition(0);
delay(2000);
}
void loop()
{
for (pos = 0; pos <= 4.5; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servo01.write(pos); // tell servo to go to position in variable 'pos'
delay(100); // waits 100ms for the servo to reach the position
}
delay(10);
for (pos = 4.5; pos >= 0; pos -= 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servo01.write(pos); // tell servo to go to position in variable 'pos'
delay(100); // waits 100ms for the servo to reach the position
}
delay(10000);
for (pos = 0; pos <= 4.5; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servo01.write(pos); // tell servo to go to position in variable 'pos'
delay(80); // waits 80ms for the servo to reach the position
}
delay(10);
for (pos =4.5; pos >= 0; pos -= 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servo01.write(pos); // tell servo to go to position in variable 'pos'
delay(80); // waits 80ms for the servo to reach the position
}
delay(10000);
while (STEPPER.currentPosition() != -600) { //
STEPPER.setSpeed(-1000);
STEPPER.run();
}
STEPPER.setCurrentPosition(0);
delay(2000);
for (pos = 0; pos <= 4.5; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servo01.write(pos); // tell servo to go to position in variable 'pos'
delay(80); // waits 15ms for the servo to reach the position
}
delay(20);
for (pos =4.5; pos >= 0; pos -= 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servo01.write(pos); // tell servo to go to position in variable 'pos'
delay(80); // waits 80ms for the servo to reach the position
}
delay(7000);
while (STEPPER.currentPosition() != -550) {
STEPPER.setSpeed(-1000);
STEPPER.run();
}
STEPPER.setCurrentPosition(0);
delay(2000);
for (pos = 0; pos <= 5; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servo01.write(pos); // tell servo to go to position in variable 'pos'
delay(25); // waits 25ms for the servo to reach the position
}
delay(20);
for (pos =5; pos >= 0; pos -= 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servo01.write(pos); // tell servo to go to position in variable 'pos'
delay(25); // waits 25ms for the servo to reach the position
}
delay(7000);
while (STEPPER.currentPosition() != 1150) {
STEPPER.setSpeed(1000);
STEPPER.run();
}
STEPPER.setCurrentPosition(0);
delay(3000);
for (pos = 0; pos <= 5; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servo01.write(pos); // tell servo to go to position in variable 'pos'
delay(25); // waits 25ms for the servo to reach the position
}
delay(20);
for (pos =5; pos >= 0; pos -= 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servo01.write(pos); // tell servo to go to position in variable 'pos'
delay(25); // waits 25ms for the servo to reach the position
}
delay(7000);
for (pos = 0; pos <= 5; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servo01.write(pos); // tell servo to go to position in variable 'pos'
delay(25); // waits 25ms for the servo to reach the position
}
delay(20);
for (pos =5; pos >= 0; pos -= 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
servo01.write(pos); // tell servo to go to position in variable 'pos'
delay(25); // waits 25ms for the servo to reach the position
}
delay(70000000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment