研究了好几天 终于 用模型遥控器 控制了 4个继电器 兴奋 咱的模型坦克 有救了 上代码 只用了一个通道试了一下
int ch1;
int ch2;
int ch3;
int ch4;
int move;
int turn;
void setup()
{
pinMode(3, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(9, INPUT);
Serial.begin(9600);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
}
void loop() {
ch1 = pulseIn(3, HIGH, 25000);
ch2 = pulseIn(5, HIGH, 25000);
ch3 = pulseIn(6, HIGH, 25000);
ch4 = pulseIn(9, HIGH, 25000);
move =map(ch1,1140,1900,1140,1900);
if(move<1200){digitalWrite(10,HIGH);}
if(move>1300){digitalWrite(10,LOW);}
if(move>1800){digitalWrite(11,HIGH);}
if(move<1700){digitalWrite(11,LOW);}
Serial.print("Channel 1:");
Serial.println(ch1);
Serial.print("Channel 2:");
Serial.println(ch2);
Serial.print("Channel 3:");
Serial.println(ch3);
Serial.print("Channel 4:");
Serial.println(ch4);
delay(100);
}
|