//ULN2003的四个端口
int p1=2;
int p2=3;
int p3=4;
int p4=5;
void setup()
{
pinMode(p1,OUTPUT);
pinMode(p2,OUTPUT);
pinMode(p3,OUTPUT);
pinMode(p4,OUTPUT);
}
int i=0;
void loop()
{
switch(i)
{
case 0:
digitalWrite(p1,HIGH);
digitalWrite(p2,LOW);
digitalWrite(p3,LOW);
digitalWrite(p4,LOW);
i++;
//此延时为步进电机最快速度
delay(2);
break;
case 1:
//其实此部分可以使用移位运算,不知怎么弄?
digitalWrite(p1,LOW);
digitalWrite(p2,HIGH);
digitalWrite(p3,LOW);
digitalWrite(p4,LOW);
i++;
delay(2);
break;
case 2:
digitalWrite(p1,LOW);
digitalWrite(p2,LOW);
digitalWrite(p3,HIGH);
digitalWrite(p4,LOW);
i++;
delay(2);
break;
case 3:
digitalWrite(p1,LOW);
digitalWrite(p2,LOW);
digitalWrite(p3,LOW);
digitalWrite(p4,HIGH);
i=0;
delay(2);
break;
}
}
|