fixed some BUGs
This commit is contained in:
parent
209f13c5b4
commit
20faf372b5
|
@ -7,7 +7,7 @@
|
||||||
RF24 radio(7,8);//端口可能要改
|
RF24 radio(7,8);//端口可能要改
|
||||||
SoftwareSerial sendingSerial(5,6);
|
SoftwareSerial sendingSerial(5,6);
|
||||||
String sending="";
|
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 propeller=0,rudder=0,dist;//propeller为螺旋桨(0-1023,512为静止),rudder为舵(0-1023,512为静止)
|
||||||
long sending_signal=0;//发送的信号
|
long sending_signal=0;//发送的信号
|
||||||
long response=0;
|
long response=0;
|
||||||
|
@ -17,15 +17,30 @@ void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
sendingSerial.begin(38400);
|
sendingSerial.begin(38400);
|
||||||
radio.begin();
|
radio.begin();
|
||||||
//radio.setChannel(114);//设置信道,114号通道
|
//radio.setChannel(115);//设置信道,115号通道
|
||||||
|
radio.setDataRate(RF24_250KBPS);
|
||||||
|
radio.setRetries(3, 5);
|
||||||
radio.openWritingPipe(addresser);
|
radio.openWritingPipe(addresser);
|
||||||
radio.openReadingPipe(1,addresser);
|
radio.openReadingPipe(1,addresser);
|
||||||
radio.setPALevel(RF24_PA_MIN);
|
radio.setPALevel(RF24_PA_MIN);
|
||||||
Timer1.initialize(interval);
|
//Timer1.initialize(interval);
|
||||||
Timer1.attachInterrupt(send);
|
//Timer1.attachInterrupt(send);
|
||||||
radio.startListening();
|
radio.startListening();
|
||||||
}
|
}
|
||||||
void send(){
|
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();
|
time=millis();
|
||||||
//Serial.println("send");
|
//Serial.println("send");
|
||||||
sending_signal=0;
|
sending_signal=0;
|
||||||
|
@ -37,20 +52,11 @@ void send(){
|
||||||
sending_signal+=propeller;
|
sending_signal+=propeller;
|
||||||
sending_signal+=rudder*1000;
|
sending_signal+=rudder*1000;
|
||||||
sending_signal+=1000000;
|
sending_signal+=1000000;
|
||||||
radio.write(&sending_signal,sizeof(sending_signal));
|
bool b=radio.write(&sending_signal,sizeof(sending_signal));
|
||||||
// Serial.println(propeller);
|
Serial.println(b);
|
||||||
// Serial.println(rudder);
|
|
||||||
// Serial.print("propeller sent ");
|
|
||||||
// Serial.println(propeller);
|
|
||||||
// Serial.print("rudder sent ");
|
|
||||||
// Serial.println(rudder);
|
|
||||||
// Serial.println(sending_signal);
|
|
||||||
radio.startListening();
|
radio.startListening();
|
||||||
//Serial.println(millis()-time);
|
delay(interval);
|
||||||
}
|
//Serial.println("loop");
|
||||||
void loop() {
|
|
||||||
// put your main code here, to run repeatedly:
|
|
||||||
Serial.println("loop");
|
|
||||||
if(radio.available()){
|
if(radio.available()){
|
||||||
Serial.print("response:");
|
Serial.print("response:");
|
||||||
radio.read(&response,sizeof(response));
|
radio.read(&response,sizeof(response));
|
||||||
|
|
Loading…
Reference in New Issue