nearly complete

This commit is contained in:
clf3 2023-09-12 01:59:02 +08:00
parent f76e1f5594
commit 3510e3cd16
3 changed files with 26 additions and 22 deletions

View File

@ -6,13 +6,14 @@ bool flag=false;
SoftwareSerial sendingSerial(5,6); SoftwareSerial sendingSerial(5,6);
SoftwareSerial bluetoothSerial(7,8); SoftwareSerial bluetoothSerial(7,8);
String sending="",received=""; String sending="",received="";
const int Rp=0,Rr=1,interval=100;//Rp,Rr 分别为两个遥杆的接口 const int Rp=3,Rr=2,interval=100;//Rp,Rr 分别为两个遥杆的接口
long propeller=0,rudder=0,dist;//propeller为螺旋桨0-1023512为静止rudder为舵0-1023512为静止 long propeller=0,rudder=0,dist;//propeller为螺旋桨0-1023512为静止rudder为舵0-1023512为静止
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; long time=0;
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
sendingSerial.begin(38400); sendingSerial.begin(38400);
bluetoothSerial.begin(57600); bluetoothSerial.begin(57600);
@ -37,6 +38,8 @@ void loop() {
sending_signal=0; sending_signal=0;
propeller=analogRead(Rp); propeller=analogRead(Rp);
rudder=analogRead(Rr); rudder=analogRead(Rr);
propeller=propeller*1.41;
rudder=rudder*1.41;
if(propeller>=1000)propeller=999; if(propeller>=1000)propeller=999;
if(rudder>=1000)rudder=999; if(rudder>=1000)rudder=999;
sending_signal+=propeller; sending_signal+=propeller;

View File

@ -2,7 +2,7 @@
#include<SoftwareSerial.h> #include<SoftwareSerial.h>
#include "Ucglib.h" #include "Ucglib.h"
#define interruptPin 2 #define interruptPin 2
SoftwareSerial sendingSerial(6,7); SoftwareSerial sendingSerial(5,6);
int Ymax = 128; //屏幕的竖向像素数 int Ymax = 128; //屏幕的竖向像素数
int Xmax = 160; //屏幕的横向像素数 int Xmax = 160; //屏幕的横向像素数
int Xcent = Xmax / 2; //x中位 int Xcent = Xmax / 2; //x中位
@ -67,6 +67,7 @@ void loop() {
else{ else{
rec=true; rec=true;
sendingSerial.read();//把换行符读掉 sendingSerial.read();//把换行符读掉
Serial.println(received);
if(received[0]=='1'){ if(received[0]=='1'){
ignoreClr=false; ignoreClr=false;
distance=received.substring(4).toInt();//个十百3位数 distance=received.substring(4).toInt();//个十百3位数

View File

@ -70,8 +70,8 @@ long confirm(long x){
} }
void loop() { void loop() {
int distance=0; int distance=0;
Serial.print("s: "); // Serial.print("s: ");
Serial.println(status); // Serial.println(status);
if(status==0){ if(status==0){
if(x<180){ if(x<180){
x+=2; x+=2;
@ -86,11 +86,11 @@ void loop() {
//response=1000000+x*1000+distance; //response=1000000+x*1000+distance;
response=0; response=0;
response+=distance; response+=distance;
Serial.println(response); //Serial.println(response);
response+=(long)x*1000; response+=(long)x*1000;
Serial.println(response); //Serial.println(response);
response+=1000000; response+=1000000;
Serial.println(response); //Serial.println(response);
} }
else if(status==1){ else if(status==1){
if(x>0){ if(x>0){
@ -105,11 +105,11 @@ void loop() {
//response=1000000+x*1000+distance; //response=1000000+x*1000+distance;
response=0; response=0;
response+=distance; response+=distance;
Serial.println(response); //Serial.println(response);
response+=(long)x*1000; response+=(long)x*1000;
Serial.println(response); //Serial.println(response);
response+=1000000; response+=1000000;
Serial.println(response); //Serial.println(response);
//send distance //send distance
} }
else if(status=2){ else if(status=2){
@ -128,11 +128,11 @@ void loop() {
} }
sending=String(response); sending=String(response);
Serial.print("x: "); // Serial.print("x: ");
Serial.println(x); // Serial.println(x);
Serial.print("d: "); // Serial.print("d: ");
Serial.println(distance); // Serial.println(distance);
Serial.println(response); // Serial.println(response);
Serial.println(sending); Serial.println(sending);
bluetoothSerial.println(sending); bluetoothSerial.println(sending);
delay(interval); delay(interval);
@ -147,7 +147,7 @@ void loop() {
} }
else{ else{
bluetoothSerial.read();//把换行符读掉 bluetoothSerial.read();//把换行符读掉
//Serial.println(received); Serial.println(received);
//Serial.println(received.length()); //Serial.println(received.length());
//content=toInt(received); //content=toInt(received);
if(received[0]=='1'&&received.length()-1==7){ if(received[0]=='1'&&received.length()-1==7){
@ -160,8 +160,8 @@ void loop() {
digitalWrite(IN1,LOW); digitalWrite(IN1,LOW);
analogWrite(PWM,zheng); analogWrite(PWM,zheng);
z=zheng; z=zheng;
//Serial.println("forward propelling"); Serial.println("forward propelling");
//Serial.println(z); Serial.println(z);
} }
else if(propeller<449){ else if(propeller<449){
long fan=255-0.568*propeller; long fan=255-0.568*propeller;
@ -169,15 +169,15 @@ void loop() {
digitalWrite(IN2,LOW); digitalWrite(IN2,LOW);
analogWrite(PWM,fan); analogWrite(PWM,fan);
z=fan; z=fan;
//Serial.println("back propelling"); Serial.println("back propelling");
//Serial.println(z); Serial.println(z);
} }
} }
else if(propeller<=550||propeller>=449){ else if(propeller<=550||propeller>=449){
z=0; z=0;
analogWrite(PWM,0); analogWrite(PWM,0);
//Serial.println("stop propelling"); Serial.println("stop propelling");
//Serial.println(z); Serial.println(z);
} }
//Serial.println("inputing ruddering"); //Serial.println("inputing ruddering");
if(rudder>550||rudder<449) if(rudder>550||rudder<449)