fixed some BUGs
This commit is contained in:
parent
b5f240f1b2
commit
209f13c5b4
|
@ -7,11 +7,12 @@
|
||||||
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=20;//Rp,Rr 分别为两个遥杆的接口
|
const int Rp=0,Rr=1,interval=100;//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;
|
||||||
const byte addresser[6]={"00001"};//创建通信通道地址,6用来写,8用来读
|
const byte addresser[6]={"00001"};//创建通信通道地址,6用来写,8用来读
|
||||||
|
long time=0;
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
sendingSerial.begin(38400);
|
sendingSerial.begin(38400);
|
||||||
|
@ -19,12 +20,14 @@ void setup() {
|
||||||
//radio.setChannel(114);//设置信道,114号通道
|
//radio.setChannel(114);//设置信道,114号通道
|
||||||
radio.openWritingPipe(addresser);
|
radio.openWritingPipe(addresser);
|
||||||
radio.openReadingPipe(1,addresser);
|
radio.openReadingPipe(1,addresser);
|
||||||
radio.setPALevel(RF24_PA_HIGH);
|
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(){
|
||||||
|
time=millis();
|
||||||
|
//Serial.println("send");
|
||||||
sending_signal=0;
|
sending_signal=0;
|
||||||
radio.stopListening();
|
radio.stopListening();
|
||||||
propeller=analogRead(Rp);
|
propeller=analogRead(Rp);
|
||||||
|
@ -43,11 +46,13 @@ void send(){
|
||||||
// Serial.println(rudder);
|
// Serial.println(rudder);
|
||||||
// Serial.println(sending_signal);
|
// Serial.println(sending_signal);
|
||||||
radio.startListening();
|
radio.startListening();
|
||||||
|
//Serial.println(millis()-time);
|
||||||
}
|
}
|
||||||
void loop() {
|
void loop() {
|
||||||
// put your main code here, to run repeatedly:
|
// put your main code here, to run repeatedly:
|
||||||
|
Serial.println("loop");
|
||||||
if(radio.available()){
|
if(radio.available()){
|
||||||
|
Serial.print("response:");
|
||||||
radio.read(&response,sizeof(response));
|
radio.read(&response,sizeof(response));
|
||||||
Serial.println(response);
|
Serial.println(response);
|
||||||
if(response%1000000==1){
|
if(response%1000000==1){
|
||||||
|
|
|
@ -59,12 +59,13 @@ void setup()
|
||||||
pinMode(A1,INPUT);
|
pinMode(A1,INPUT);
|
||||||
pinMode(A2,INPUT);
|
pinMode(A2,INPUT);
|
||||||
MyServo.write(angle);
|
MyServo.write(angle);
|
||||||
|
|
||||||
RadarServo.write(0);
|
RadarServo.write(0);
|
||||||
radio.begin();
|
radio.begin();
|
||||||
//radio.setChannel(114);
|
//radio.setChannel(114);
|
||||||
radio.openReadingPipe(1,addresses); //接收通道,
|
radio.openReadingPipe(1,addresses); //接收通道,
|
||||||
radio.openWritingPipe(addresses);//发送通道
|
radio.openWritingPipe(addresses);//发送通道
|
||||||
radio.setPALevel(RF24_PA_HIGH); //设置功率放大器级别,将其设置为最小值
|
radio.setPALevel(RF24_PA_MIN); //设置功率放大器级别,将其设置为最小值
|
||||||
delay(1000);
|
delay(1000);
|
||||||
MyServo.write(45);
|
MyServo.write(45);
|
||||||
}
|
}
|
||||||
|
@ -178,7 +179,7 @@ void loop() {
|
||||||
//send clear
|
//send clear
|
||||||
response=2000000;
|
response=2000000;
|
||||||
}
|
}
|
||||||
radio.write(response,sizeof(response));
|
radio.write(&response,sizeof(response));
|
||||||
//delay(20-distance/17);
|
//delay(20-distance/17);
|
||||||
Serial.println(distance);
|
Serial.println(distance);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue