From 209f13c5b4f121092392665ce0b60fff9efc8e7c Mon Sep 17 00:00:00 2001 From: clf3 Date: Fri, 8 Sep 2023 21:41:54 +0800 Subject: [PATCH] fixed some BUGs --- remote_controler/remote_controler.ino | 11 ++++++++--- ship/ship.ino | 5 +++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/remote_controler/remote_controler.ino b/remote_controler/remote_controler.ino index e621535..760a84c 100644 --- a/remote_controler/remote_controler.ino +++ b/remote_controler/remote_controler.ino @@ -7,11 +7,12 @@ RF24 radio(7,8);//端口可能要改 SoftwareSerial sendingSerial(5,6); 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 sending_signal=0;//发送的信号 long response=0; const byte addresser[6]={"00001"};//创建通信通道地址,6用来写,8用来读 +long time=0; void setup() { Serial.begin(9600); sendingSerial.begin(38400); @@ -19,12 +20,14 @@ void setup() { //radio.setChannel(114);//设置信道,114号通道 radio.openWritingPipe(addresser); radio.openReadingPipe(1,addresser); - radio.setPALevel(RF24_PA_HIGH); + radio.setPALevel(RF24_PA_MIN); Timer1.initialize(interval); Timer1.attachInterrupt(send); radio.startListening(); } void send(){ + time=millis(); + //Serial.println("send"); sending_signal=0; radio.stopListening(); propeller=analogRead(Rp); @@ -43,11 +46,13 @@ void send(){ // Serial.println(rudder); // Serial.println(sending_signal); radio.startListening(); + //Serial.println(millis()-time); } void loop() { // put your main code here, to run repeatedly: + Serial.println("loop"); if(radio.available()){ - + Serial.print("response:"); radio.read(&response,sizeof(response)); Serial.println(response); if(response%1000000==1){ diff --git a/ship/ship.ino b/ship/ship.ino index 6fa10ab..e52aa48 100644 --- a/ship/ship.ino +++ b/ship/ship.ino @@ -59,12 +59,13 @@ void setup() pinMode(A1,INPUT); pinMode(A2,INPUT); MyServo.write(angle); + RadarServo.write(0); radio.begin(); //radio.setChannel(114); radio.openReadingPipe(1,addresses); //接收通道, radio.openWritingPipe(addresses);//发送通道 - radio.setPALevel(RF24_PA_HIGH); //设置功率放大器级别,将其设置为最小值 + radio.setPALevel(RF24_PA_MIN); //设置功率放大器级别,将其设置为最小值 delay(1000); MyServo.write(45); } @@ -178,7 +179,7 @@ void loop() { //send clear response=2000000; } - radio.write(response,sizeof(response)); + radio.write(&response,sizeof(response)); //delay(20-distance/17); Serial.println(distance); }