1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| /*
Stepper Motor Test
stepper-test01.ino
Uses MA860H or similar Stepper Driver Unit
Has speed control & reverse switch
DroneBot Workshop 2019
https://dronebotworkshop.com
*/
// Defin pins
int reverseSwitch = 2; // Push button for reverse
int startSwitch = 3; // Push button for start
int stopSwitch = 4; // Push button for stop
boolean enMarche = false; // false = Arret
int driverPUL = 7; // PUL- pin
int driverDIR = 6; // DIR- pin
int spd = A0; // Potentiometer
// Variables
int pd = 500; // Pulse Delay period
boolean setdir = LOW; // Set Direction
// Interrupt Handler
void revmotor (){
setdir = !setdir;
}
void setup() {
pinMode (driverPUL, OUTPUT);
pinMode (driverDIR, OUTPUT);
pinMode (reverseSwitch, INPUT);
pinMode (startSwitch, INPUT_PULLUP);
pinMode (stopSwitch, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(reverseSwitch), revmotor, FALLING);
}
void loop() {
if (digitalRead(startSwitch) == LOW) // Si bouton start presse
{
enMarche = true;
}
if (digitalRead(stopSwitch) == LOW) // Si bouton stop presse
{
enMarche = false;
}
pd = map((analogRead(spd)),0,1023,2000,50);
digitalWrite(driverDIR,setdir);
if (enMarche)
{
digitalWrite(driverPUL,HIGH);
delayMicroseconds(pd);
digitalWrite(driverPUL,LOW);
delayMicroseconds(pd);
}
} |
Partager