|
本帖最后由 AnnryLeen 于 2013-7-14 16:16 编辑
手头有一块RG100A的路由器 之前别的小车用的 已经刷好Openwrt的WIFI小车固件
还有Arduino UNO的板子和一块L298N的电机驱动板和四个马达
想拼成一个WIFI小车,可是不知道该L298N和Arduino怎么连线
RG100A的TTL引脚定义也忘了是什么样的了
还有 在Arduino单片机部分使用如下的源代码可以使用兼容L298N和论坛的上位机么?
希望各位大侠赐教,不胜感激(图片已经加在帖子后面)
===============================================
// motor A
int dir1PinA = 13;
int dir2PinA = 12;
int speedPinA = 10;
// motor B
int dir1PinB = 9;
int dir2PinB = 8;
int speedPinB = 6;
int LED = 13;
int speed;
int dir;
int buffer[3];
int Serial_flag;
int date_index=0;
void setup()
{
pinMode(dir1PinA,OUTPUT);
pinMode(dir2PinA,OUTPUT);
pinMode(speedPinA,OUTPUT);
pinMode(dir1PinB,OUTPUT);
pinMode(dir2PinB,OUTPUT);
pinMode(speedPinB,OUTPUT);
pinMode(LED,OUTPUT);
Serial.begin(9600); // 打开串口,设置波特率为9600 bps
speed = 0;
dir = 1;
}
void MOTOA(int speed,int dir)
{
analogWrite(speedPinA,speed);
if (dir == 1)
{
digitalWrite(dir1PinA,LOW);
digitalWrite(dir2PinA,HIGH);
}
else
{
digitalWrite(dir1PinA,LOW);
digitalWrite(dir2PinA,LOW);
}
}
void MOTOB(int speed,int dir)
{
analogWrite(speedPinB,speed);
if (dir == 1)
{
digitalWrite(dir1PinB,LOW);
digitalWrite(dir2PinB,HIGH);
}
else
{
digitalWrite(dir1PinB,LOW);
digitalWrite(dir2PinB,LOW);
}
}
void MOTOBACK(int speed)
{
analogWrite(speedPinB,speed);
analogWrite(speedPinA,speed);
digitalWrite(dir1PinB,HIGH);
digitalWrite(dir2PinB,LOW);
digitalWrite(dir1PinA,HIGH);
digitalWrite(dir2PinA,LOW);
}
void Communication_Decode()
{
if(buffer[0]==0x00)
{
switch(buffer[1])
{
case 0x01: MOTOA(150,1);MOTOB(0,0);return;
case 0x02: MOTOA(0,0); MOTOB(150,1); return;
case 0x03: MOTOBACK(200); return;
case 0x04:
MOTOA(220,1);
MOTOB(220,1);
return;
case 0x00:
MOTOA(0,0);
MOTOB(0,0);
return;
}
}
}
void loop()
{
int temp_char;
while(Serial.available() > 0)
{
temp_char = Serial.read();
if(temp_char!=-1)
{
if(Serial_flag==0)
{
if(temp_char==0xff)
{
Serial_flag = 1;
}
}
else
{
if(temp_char==0xff)
{
Serial_flag = 0;
if(date_index==3)
{
Communication_Decode();
}
date_index = 0;
}
else
{
buffer[date_index]=temp_char;
Serial.println(buffer[date_index],HEX);
date_index++;
}
}
}
}
}
==============================================
|
|