|
/* motor-1-axe.c
|
|
|
|
Copyright (c) 2023- BLANC Frédéric (LAAS-CNRS)
|
|
|
|
motor-1-axe is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
motor-1-axe is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with motor-1-axe. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
#include <Arduino.h>
|
|
#include "AccelStepper.h"
|
|
|
|
// for the Arduino Uno + CNC shield V3 + TMC2202 1/256
|
|
|
|
#define FIRMWARE 20231117
|
|
|
|
#define MOTOR_X_ENABLE_PIN 8
|
|
#define MOTOR_X_STEP_PIN 2
|
|
#define MOTOR_X_DIR_PIN 5
|
|
|
|
#define SWUP 14 // CNC Abort rota
|
|
#define SWDOWN 15 // CNC Hold
|
|
|
|
#define UC_ENABLE 12 // CNC SpnEn
|
|
#define UC_STEP
|
|
#define UC_DIR 13 // CNC SpnDir
|
|
|
|
AccelStepper motor_X(1, MOTOR_X_STEP_PIN, MOTOR_X_DIR_PIN);
|
|
|
|
void setup()
|
|
{
|
|
pinMode(SWUP,INPUT_PULLUP);
|
|
pinMode(SWDOWN,INPUT_PULLUP);
|
|
|
|
pinMode(UC_ENABLE,OUTPUT);
|
|
digitalWrite(UC_ENABLE, LOW);
|
|
pinMode(UC_DIR,OUTPUT);
|
|
digitalWrite(UC_DIR, LOW);
|
|
|
|
motor_X.setEnablePin(MOTOR_X_ENABLE_PIN);
|
|
motor_X.setPinsInverted(false, false, true);
|
|
motor_X.setAcceleration(2560);
|
|
motor_X.move(25600);
|
|
motor_X.setMaxSpeed(1000000);
|
|
motor_X.setSpeed(25600);
|
|
motor_X.enableOutputs();
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
if (digitalRead(SWUP)==LOW)
|
|
{
|
|
digitalWrite(UC_ENABLE, HIGH);
|
|
digitalWrite(UC_DIR, LOW);
|
|
motor_X.run();
|
|
}else if (digitalRead(SWDOWN)==LOW)
|
|
{
|
|
digitalWrite(UC_ENABLE, HIGH);
|
|
digitalWrite(UC_DIR, HIGH);
|
|
motor_X.run();
|
|
}else
|
|
{
|
|
digitalWrite(UC_ENABLE, LOW);
|
|
digitalWrite(UC_DIR, LOW);
|
|
}
|
|
|
|
|
|
}
|