(old)Arduino

const int directionPin1 =  7;
const int directionPin2 =  9;
const int stepPin1 =  2;
const int stepPin2 =  4;
const int ledPin =  13;
long interval = 40; // ‘interval’ is the delay after each step.
int steps=1; // ‘steps’ is the number of steps the stepper is performing for each comand recieved.

void setup()
{
pinMode(directionPin1,OUTPUT);
pinMode(directionPin2,OUTPUT);
pinMode(stepPin1, OUTPUT);
pinMode(stepPin2, OUTPUT);
pinMode(ledPin, OUTPUT);

Serial.begin(9600);
}
// ‘4’ Extend left belt
// ‘7’ Shoten left belt
// ‘6’ Extend right belt
// ‘9’ Shoten right belt
void loop()
{
// Variables
int ch,i;

if (Serial.available())
{
ch = Serial.read();
if (ch-48==4
)
{
digitalWrite(directionPin1,HIGH);
for (i=0;i<=steps;i++)
{
digitalWrite(stepPin1,HIGH);
digitalWrite(ledPin,HIGH);
delay(interval);
digitalWrite(stepPin1,LOW);
digitalWrite(ledPin,LOW);
}
}
if (ch-48==7)
{
digitalWrite(directionPin1,LOW);
for (i=0;i<=steps;i++)
{
digitalWrite(stepPin1,HIGH);
digitalWrite(ledPin,HIGH);
delay(interval);
digitalWrite(stepPin1,LOW);
digitalWrite(ledPin,LOW);
}
}

if (ch-48==9
)
{
digitalWrite(directionPin2,HIGH);
for (i=0;i<=steps;i++)
{
digitalWrite(stepPin2,HIGH);
digitalWrite(ledPin,HIGH);
delay(interval);
digitalWrite(stepPin2,LOW);
digitalWrite(ledPin,LOW);
}
}
if (ch-48==6
)
{
digitalWrite(directionPin2,LOW);
for (i=0;i<=steps
;i++)
{
digitalWrite(stepPin2,HIGH);
digitalWrite(ledPin,HIGH);
delay(interval);
digitalWrite(stepPin2,LOW);
digitalWrite(ledPin,LOW);
}
}

}

}

Comments

comments

Leave a Reply

Your email address will not be published. Required fields are marked *