|
- const int dirPin = 2;
- const int stepPin = 3;
- const int stepsPerRevolution = 20000;
- int ch1 = 12;int val = 0;int val1 = 0;int delaytime = 0;
- void setup()
- {
- Serial.begin(115200);
- pinMode(ch1, INPUT_PULLUP);
- }
- void loop() {
- val = pulseIn(ch1, HIGH); //读取1通道PWM数值
- delay(50);
- val = pulseIn(ch1, HIGH,10000);
- if(val< 995) val = 995; //设置最小值
- if(val> 1985) val = 1985;//设置最大值
- val1 = map(val, 995, 1985 , 50, 400); //设置映射范围
- if(val1> 200) val1 = 200; //设置摇杆左侧数值区间
- delaytime=val1; //改变转速
- Serial.print("Val1="); Serial.println(val1);
- Serial.print("VaL="); Serial.println(val);
- Serial.print("delaytime="); Serial.println(delaytime);
- if (val<1350){
- digitalWrite(dirPin, HIGH);
- for (int x = 0; x < stepsPerRevolution; x++)
- {
- digitalWrite(stepPin, HIGH);
- delayMicroseconds(delaytime);
- digitalWrite(stepPin, LOW);
- delayMicroseconds(delaytime);
- }
复制代码 使用arduino NANO读取模型接收机1通道信号通过A4988控制步进电机方向和速度,但是不知道为什么,摇杆复位就不卡顿推动摇杆运行程序就卡顿,是硬件门体还是我程序有问题啊
求大佬救我,
|
|