
再发一下Arduino代码求大神大哥们教教
#include <Servo.h>
#include <math.h>
#include <SoftwareSerial.h>
SoftwareSerial softSerial(10, 11);
volatile float cx;
volatile float cy;
volatile float cl;
float p[3];
float pos1=0;
float pos3=0;
float z=0;
float k=0;
String json;
Servo myservo1,myservo2,myservo3,myservo4;
void setup()
{
cx=0;
cy=0;
cl=0;
Serial.begin(9600);
softSerial.begin(9600);
myservo1.attach(2);
myservo2.attach(4);
myservo3.attach(7);
myservo4.attach(8);
}
void loop()
{
if (softSerial.available()>0)
{
p[3]=float(softSerial.read());
}
cl=p[0];
cx=p[1];
cy=p[2];
z=sqrt(cl*cl-cx*cx-cy*cy);
pos1=(atan(cx/(23+z))*180)/3.1415926;
k=sqrt((z+23)*(z+23)+cx*cx);
pos3=(atan(cy/k)*180)/3.1415926;
delay(5000);
myservo1.write(pos1);
myservo2.write(90);
myservo3.write(pos3);
myservo4.write(180);
Serial.println(p[0]);
}
https://book.openmv.cc/MCU/serial2.html
按照这个的代码改一下。
我已经知道是因为p的坐标值是字符串了,就是不知道怎么把他换成整形
看我上面的链接。string.toInt()方法。