//StandardPWMDCcontrol
intE1=5;//M1SpeedControl
intE2=6;//M2SpeedControl
intM1=4;//M1DirectionControl
intM2=7;//M1DirectionControl
///ForpreviousRomeo,pleaseusethesepins.
//intE1=6;//M1SpeedControl
//intE2=9;//M2SpeedControl
//intM1=7;//M1DirectionControl
//intM2=8;//M1DirectionControl
voidstop(void)//Stop
{
digitalWrite(E1,LOW);
digitalWrite(E2,LOW);
}
voidadvance(chara,charb)//Moveforward
{
analogWrite(E1,a);//PWMSpeedControl
digitalWrite(M1,HIGH);
analogWrite(E2,b);
digitalWrite(M2,HIGH);
}
voidback_off(chara,charb)//Movebackward
{
analogWrite(E1,a);
digitalWrite(M1,LOW);
analogWrite(E2,b);
digitalWrite(M2,LOW);
}
voidturn_L(chara,charb)//TurnLeft
{
analogWrite(E1,a);
digitalWrite(M1,LOW);
analogWrite(E2,b);
digitalWrite(M2,HIGH);
}
voidturn_R(chara,charb)//TurnRight
{
analogWrite(E1,a);
digitalWrite(M1,HIGH);
analogWrite(E2,b);
digitalWrite(M2,LOW);
}
voidsetup(void)
{
inti;
for(i=4;i<=7;i++)
pinMode(i,OUTPUT);
Serial.begin(19200);//SetBaudRate
Serial.println("Runkeyboardcontrol");
}
voidloop(void)
{
if(Serial.available()){
charval=Serial.read();
if(val!=‐1)
{
switch(val)
{
case'w'://MoveForward
advance(255,255);//moveforwardinmaxspeed
break;
case's'://MoveBackward
back_off(255,255);//movebackinmaxspeed
break;
case'a'://TurnLeft
turn_L(100,100);
break;
case'd'://TurnRight
turn_R(100,100);
break;
case'z':
Serial.println("Hello");
break;
case'x':
stop();