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 bluetoothSerial(7,8);
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 sending_signal=0;//发送的信号
long response=0;
//const byte addresser[6]={"00001"};//创建通信通道地址6用来写8用来读
long time=0;
void setup() {
Serial.begin(9600);
sendingSerial.begin(38400);
bluetoothSerial.begin(57600);
@ -37,6 +38,8 @@ void loop() {
sending_signal=0;
propeller=analogRead(Rp);
rudder=analogRead(Rr);
propeller=propeller*1.41;
rudder=rudder*1.41;
if(propeller>=1000)propeller=999;
if(rudder>=1000)rudder=999;
sending_signal+=propeller;

View File

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

View File

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