diff --git a/remote_controler/remote_controler.ino b/remote_controler/remote_controler.ino index 760a84c..87e9703 100644 --- a/remote_controler/remote_controler.ino +++ b/remote_controler/remote_controler.ino @@ -7,7 +7,7 @@ RF24 radio(7,8);//端口可能要改 SoftwareSerial sendingSerial(5,6); String sending=""; -const int Rp=0,Rr=1,interval=100;//Rp,Rr 分别为两个遥杆的接口 +const int Rp=0,Rr=1,interval=20;//Rp,Rr 分别为两个遥杆的接口 long propeller=0,rudder=0,dist;//propeller为螺旋桨(0-1023,512为静止),rudder为舵(0-1023,512为静止) long sending_signal=0;//发送的信号 long response=0; @@ -17,15 +17,30 @@ void setup() { Serial.begin(9600); sendingSerial.begin(38400); radio.begin(); - //radio.setChannel(114);//设置信道,114号通道 + //radio.setChannel(115);//设置信道,115号通道 + radio.setDataRate(RF24_250KBPS); + radio.setRetries(3, 5); radio.openWritingPipe(addresser); radio.openReadingPipe(1,addresser); radio.setPALevel(RF24_PA_MIN); - Timer1.initialize(interval); - Timer1.attachInterrupt(send); + //Timer1.initialize(interval); + //Timer1.attachInterrupt(send); radio.startListening(); } void send(){ + + // Serial.println(propeller); + // Serial.println(rudder); + // Serial.print("propeller sent "); + // Serial.println(propeller); + // Serial.print("rudder sent "); + // Serial.println(rudder); + // Serial.println(sending_signal); + + //Serial.println(millis()-time); +} +void loop() { + // put your main code here, to run repeatedly: time=millis(); //Serial.println("send"); sending_signal=0; @@ -37,20 +52,11 @@ void send(){ sending_signal+=propeller; sending_signal+=rudder*1000; sending_signal+=1000000; - radio.write(&sending_signal,sizeof(sending_signal)); - // Serial.println(propeller); - // Serial.println(rudder); - // Serial.print("propeller sent "); - // Serial.println(propeller); - // Serial.print("rudder sent "); - // Serial.println(rudder); - // Serial.println(sending_signal); + bool b=radio.write(&sending_signal,sizeof(sending_signal)); + Serial.println(b); radio.startListening(); - //Serial.println(millis()-time); -} -void loop() { - // put your main code here, to run repeatedly: - Serial.println("loop"); + delay(interval); + //Serial.println("loop"); if(radio.available()){ Serial.print("response:"); radio.read(&response,sizeof(response));