Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <AccelStepper.h>
  2. #include <avr/interrupt.h>
  3. #include <avr/io.h>
  4.  
  5. #define STEP_PIN 12
  6. #define DIR_PIN 13
  7. #define USART_BAUDRATE 9600
  8.  
  9. const int stepsPerRevolution = 200;
  10. const uint16_t NUMBER_OF_SPINS = 7500;
  11. const uint16_t STEPPER_MAX_SPEED = 1000;
  12. const uint8_t STEPPER_ACCELERATION = 10;
  13.  
  14. AccelStepper myStepper(1, STEP_PIN, DIR_PIN);
  15.  
  16. void setup() {
  17.   Serial.begin(9600);
  18.   Serial.println("CNC WINDING MACHINE");
  19.   Serial.println("SHUT UP AND MAKE PICKUPS!!");
  20.  
  21.   myStepper.setAcceleration(STEPPER_ACCELERATION);
  22.   myStepper.setMaxSpeed(STEPPER_MAX_SPEED);
  23.  
  24.   attachInterrupt(2, handleCommands, HIGH);
  25. }
  26.  
  27. void loop() {
  28.   myStepper.move(stepsPerRevolution *  NUMBER_OF_SPINS);
  29. }
  30.  
  31. void handleCommands() {
  32.    int i;
  33.    int length = Serial.available();
  34.  
  35.    String cmd = "";
  36.    //copy data out of the receive buffer
  37.    for(i = 0; i < length; i++) {
  38.       cmd += Serial.read();
  39.    }
  40.  
  41.    //run a string compare function, or otherwise parse the received data
  42.    if(cmd.equals("stop") ){
  43.       myStepper.stop();
  44.       Serial.println("OK. Take a cup of tea. I'll be missing you!");
  45.    } else if ( cmd.equals("start") ) {
  46.       Serial.println("Prepare to FIGHT!");
  47.       myStepper.run();
  48.    }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement