Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <AccelStepper.h>
- #include <avr/interrupt.h>
- #include <avr/io.h>
- #define STEP_PIN 12
- #define DIR_PIN 13
- #define USART_BAUDRATE 9600
- const int stepsPerRevolution = 200;
- const uint16_t NUMBER_OF_SPINS = 7500;
- const uint16_t STEPPER_MAX_SPEED = 1000;
- const uint8_t STEPPER_ACCELERATION = 10;
- AccelStepper myStepper(1, STEP_PIN, DIR_PIN);
- void setup() {
- Serial.begin(9600);
- Serial.println("CNC WINDING MACHINE");
- Serial.println("SHUT UP AND MAKE PICKUPS!!");
- myStepper.setAcceleration(STEPPER_ACCELERATION);
- myStepper.setMaxSpeed(STEPPER_MAX_SPEED);
- attachInterrupt(2, handleCommands, HIGH);
- }
- void loop() {
- myStepper.move(stepsPerRevolution * NUMBER_OF_SPINS);
- }
- void handleCommands() {
- int i;
- int length = Serial.available();
- String cmd = "";
- //copy data out of the receive buffer
- for(i = 0; i < length; i++) {
- cmd += Serial.read();
- }
- //run a string compare function, or otherwise parse the received data
- if(cmd.equals("stop") ){
- myStepper.stop();
- Serial.println("OK. Take a cup of tea. I'll be missing you!");
- } else if ( cmd.equals("start") ) {
- Serial.println("Prepare to FIGHT!");
- myStepper.run();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement