|
const int dir = 2;
const int ste = 3;
const int MaximumDelaytime = 2000;
int ch1 = 12;
int val = 0;
int val1= 0;
int delaytime = 0;
void setup() {
Serial.begin(115200);
pinMode(ch1, INPUT_PULLUP);
pinMode(ste, OUTPUT);
pinMode(dir, OUTPUT);
}
void loop() {
val = pulseIn(ch1, HIGH);
if(val< 995) val = 995;
if(val> 1985) val = 1985;
val1 = map(val, 995, 1985 , 0, 1000);
Serial.print("VaL="); Serial.println(val);
Serial.print("Val1="); Serial.println(val1);
Serial.print("delaytime="); Serial.println(delaytime);
if (val<1400){
delaytime=MaximumDelaytime*(val-325)/182;
//if (delaytime<0) delaytime=0;
digitalWrite(dir,HIGH);
digitalWrite(ste,HIGH);
delayMicroseconds(delaytime);
digitalWrite(ste,LOW);
delayMicroseconds(delaytime);
}
else if (val>1600){
delaytime=MaximumDelaytime*(694-val)/184;
// if (delaytime<0) delaytime=0;
digitalWrite(dir,LOW);
digitalWrite(ste,HIGH);
delayMicroseconds(delaytime);
digitalWrite(ste,LOW);
delayMicroseconds(delaytime);
}
}
为什么通电后电机没有明显的转速变化啊,还有各位大佬,还有其他的控制步进电机转速和方向的方法么?
|
|