const int stepPin = 3;
const int dirPin = 4;
const int Enable = 5;
const int GLED = 6;
const int RLED = 7;
const int LmtSwtch = A1;
const int Mspeed = 500;
int Lastbuttonstate = 1;
int flag1 = 0;
int StepAmount = 0;
int StepAmountSet = 6000;
int customDelay,customDelayMapped;
void setup() {
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(Enable, OUTPUT);
pinMode(LmtSwtch, INPUT_PULLUP);
pinMode(GLED, OUTPUT);
pinMode(RLED, OUTPUT);
digitalWrite(dirPin,HIGH);
digitalWrite(RLED,HIGH);
digitalWrite(GLED,HIGH);
}
void loop() {
int Buttonstate = digitalRead(LmtSwtch);
if (Buttonstate < Lastbuttonstate){
flag1 = 1;
}
Lastbuttonstate = Buttonstate;
if (flag1 == 0)
{
digitalWrite(Enable, LOW);
digitalWrite(stepPin, LOW);
}
if (flag1 == 1 && StepAmount < StepAmountSet)
{
digitalWrite(Enable, LOW);
digitalWrite(stepPin, HIGH);
delayMicroseconds(Mspeed);
digitalWrite(stepPin, LOW);
delayMicroseconds(Mspeed);
StepAmount = StepAmount + 1;
}
else {
flag1 = 0;
StepAmount = 0;
}
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.