【发布时间】:2020-03-09 13:25:44
【问题描述】:
请给我的 Arduino 狗提供此代码
但它不起作用,因为我没有将角度转换为 rad 进行 cos() 操作,但最后我需要获取角度(在 cos() 操作之后)。
const int b = 200; //Lengt
const int Pin = A0; //Pot pin
int c = 0; //Variable for Angle
int d = 0; //
int e = 0; //Final side size
void setup() {
Serial.begin(9600);
}
void loop() {
c = analogRead(Pin);//Read potval write to variable c
c = map(c, 0, 1023, 0, 180);//Map potval to Angle
c = cos(c)//Calculate Cosinus
d = b - (b * c);//200 - (200 * c)
e = sqrt(d)//Calcute √e
Serial.print(e)//Print out final side a
}
//Example:
//d = 200 − (200 * 0,6560)
//d = 200 − 131,2 = 68.8
//e = √68.8
//e = 8.29
【问题讨论】:
-
Rad to degree 与 pi 有某种关系 :) 。 (pi 甚至是一个预定义的常数)。通常,int 计算是首选,但这里不是。 cos 返回一个介于 -1 和 +1 之间的数字,因此只有三个可能的 int 结果; ( -1, 0, 1 )
标签: math arduino trigonometry robot