fixed some BUGs

This commit is contained in:
clf3 2023-09-09 19:44:10 +08:00
parent 209f13c5b4
commit 20faf372b5
1 changed files with 23 additions and 17 deletions

View File

@ -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-1023512为静止rudder为舵0-1023512为静止
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));