资源介绍
通过判断//成功实现粗略差速
int Dirmin=257;
int Dirmax=387;
int Accmin=160;
int Accmax=885;
const int xpin = A1; // x-axis
const String XHEADER = "X: ";
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(A1, INPUT);// 设置9号口为输出端口:
pinMode(A0, INPUT);// 设置10号口为输出端口:
pinMode(9, OUTPUT);// 设置9号口为输出端口:
pinMode(10, OUTPUT);// 设置10号口为输出端口:
}
void loop() {
int Dir=analogRead(xpin);
//Serial.print(XHEADER + analogRead(xpin) );
//Serial.print(analogRead(A0) );
//8 Serial.println();
// put your main code here, to run repeatedly:
int Acc=analogRead(A0);
int Acc_2 = map(Acc, Accmin,Accmax, 0, 255);
int Dir_2 = map(Dir, Dirmin, Dirmax, 0, 255);
//Serial.print(Dir);
//Serial.println();
if(Dir_2>=0&&Dir;_2<120)
{
analogWrite(9, Acc_2*Dir_2/120);
analogWrite(10, Acc_2);
}
else if(Dir_2>136&&Dir;_2<=255)
{
analogWrite(9, Acc_2);
analogWrite(10,Acc_2*(255-Dir_2)/120);
}
else if(Dir_2<=136&&Dir;_2>=120)
{
analogWrite(9, Acc_2);
analogWrite(10,Acc_2);
}
delay(300); //延时300毫秒
}