Go directly to the code and test it. There is no explosion or fire. Note that this is the video received from the receiver. The first speed is about 1/4 of the full speed. Later, a better control motherboard will be released. If you don’t have Arduino basics, don’t do it.
#define PINX 11
#define PINY 2
#define PINKG 7
#define LEDA 12
#define LEDB 13
#define PINLU 5
#define PINLD 6
#define PINRU 10
#define PINRD 9
int TZ=40;//速度调整
int speedcal=0;
int Direction;//方向原始数据
int correctionXR;//x修正后的X
int correctionXL;//x修正后的X
int spd=255;
unsigned long Speed;
unsigned long KGSG;
void motorprint();
void motorcontrol();
void dealX();//X方向调整
void motorprint()
{
pinMode(PINX, INPUT); //设置引脚为输入模式
pinMode(PINY, INPUT); //设置引脚为输入模式
pinMode(PINKG, INPUT); //设置引脚为输入模式
pinMode(8, INPUT); //设置引脚为输入模式
// pinMode(PINLU, OUTPUT); //设置引脚为输出模式
pinMode(PINLD, OUTPUT); //设置引脚为输出模式
pinMode(PINRU, OUTPUT); //设置引脚为输出模式
// pinMode(PINRD, OUTPUT); //设置引脚为输出模式
// digitalWrite(PINLU,LOW);
digitalWrite(PINLD,LOW);
digitalWrite(PINRU,LOW);
// digitalWrite(PINRD,LOW);
pinMode(LEDA, OUTPUT); //设置引脚为输出模式
}
void motorcontrol()
{
if (Direction>TZ/2+3)
{
speedcal=constrain(map((Speed+Direction),Speed,310,Speed,250),Speed,250);
// analogWrite(PINLU,speedcal);
analogWrite(PINLD,speedcal);
analogWrite(PINRU,Speed);
// analogWrite(PINRD,Speed);
}
else if (Direction<TZ/2-3)
{
speedcal=constrain(map((Speed+Direction),Speed,310,Speed,250),Speed,250);
// analogWrite(PINLU,Speed);
analogWrite(PINLD,Speed);
analogWrite(PINRU,speedcal);
// analogWrite(PINRD,speedcal);
}
else
{
// analogWrite(PINLU,Speed);
analogWrite(PINLD,Speed);
analogWrite(PINRU,Speed);
// analogWrite(PINRD,Speed);
}
}
void setup()
{
Serial.begin(19200);
motorprint();
}
void loop()
{
/*Speed =pulseIn(Y, HIGH,80000);
Direction =pulseIn(X, HIGH,80000);
KGSG = pulseIn(KG, HIGH,80000);*/
KGSG = pulseIn(PINKG, HIGH,80000);
if(KGSG<1100)
spd=3;
else if(KGSG<1700)
spd=2;
else if(KGSG<2000)
spd=1;
else
spd=255;
Speed=(constrain(map(pulseIn(PINY, HIGH,80000),989,1968,0,240), 0, 240)/spd);
Direction =constrain(map(pulseIn(PINX, HIGH,80000),998,1982,0,TZ),0,TZ);
if (pulseIn(8, HIGH,80000)<1500)
{
digitalWrite(LEDA,HIGH);
TZ=70;}
else{
digitalWrite(LEDA,LOW);
TZ=50;}
/* Serial.print("速度:");
Serial.print(Speed);
Serial.print(" 方向:");
Serial.print(Direction);
Serial.print(" 控制:");
Serial.println(KGSG);*/
if (Speed<10)
{
Speed=0;
motorcontrol();
}
else
motorcontrol();
}
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet