我正在尝试通过Arduino DUE从发送器向伺服器发送信号,并编写如下代码:
#include<Servo.h>
Servo servo1;
int ch1;
void setup() {
// put your setup code here, to run once:
pinMode(40,INPUT);
pinMode(31,OUTPUT);
servo1.attach(31);
Serial.begin(9600);
ch1 = 2000;
}
void loop() {
// put your main code here, to run repeatedly:
ch1 = pulseIn(40,HIGH,25000);
if (ch1 <= 2800 && ch1>= 1600)
{
Serial.print("Aileron:");
Serial.println(ch1);
}
delay(100);
}
如果没有if语句,我会得到平均2200的值,如果我插入if语句值降到1800.我不明白为什么?