经过判断//成功实现粗略差速intDirmin=257;intDirmax=387;intAccmin=160;intAccmax=885;constintxpin=A1;//x-axisconstStringXHEADER="X:";voidsetup(){//putyoursetupcodehere,torunonce:Serial.begin(9600);pinMode(A1,INPUT);//设置9号口为输出端口:pinMode(A0,INPUT);//设置10号口为输出端口:pinMode(9,OUTPUT);//设置9号口为输出端口:pinMode(10,OUTPUT);//设置10号口为输出端口:}voidloop(){intDir=analogRead(xpin);//Serial.print(XHEADER+analogRead(xpin));//Serial.print(analogRead(A0));//8Serial.println();//putyourmaincodehere,torunrepeatedly:intAcc=analogRead(A0);intAcc_2=map(Acc,Accmin,Accmax,0,255);intDir_2=map(Dir,Dirmin,Dirmax,0,255);//Serial.print(Dir);//Serial.println();if(Dir_2>=0&&Dir;_2136&&Dir;_2=120){analogWrite(9,Acc_2);analogWrite(10,Acc_2);}delay(300);//延时300毫秒}
1