Arduino Code:
#include <AFMotor.h> //import your motor shield libraryAF_DCMotor motor1(1,MOTOR12_64KHZ); // set up motors.
AF_DCMotor motor2(2, MOTOR12_8KHZ);
AF_DCMotor motor3(3,MOTOR12_64KHZ); // set up motors.
AF_DCMotor motor4(4, MOTOR12_8KHZ);
char data;
void setup() {
Serial.begin(9600); // begin serial communitication
Serial.println("Motor test!");
motor3.setSpeed(250); //set the speed of the motors, between 0-255
motor4.setSpeed (250);
motor1.setSpeed(250); //set the speed of the motors, between 0-255
motor2.setSpeed (250);
}
void loop() {
if(Serial.available()>0)
{
data=Serial.read();
if(data=='8')
{
Serial.println ("I AM MOVING IN FORWARD DIRECTION !" );
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
}
else if (data=='6') {
Serial.println ("I JUST TURNED RIGHT !");
delay (15);
motor1.run(BACKWARD);
motor2.run(FORWARD);
motor3.run(BACKWARD);
motor4.run(FORWARD);
}
else if (data=='4') {
Serial.println ("I JUST TURNED LEFT !");
delay (15);
motor1.run(FORWARD);
motor2.run(BACKWARD);
motor3.run(FORWARD);
motor4.run(BACKWARD);
}
else if (data=='2') {
Serial.println ("I AM MOVING IN BACKWARD DIRECTION !");
delay (15);
motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
}
else if (data=='5') {
Serial.println ("STOPPED");
delay (15);
motor3.run(RELEASE);
motor4.run(RELEASE);
motor2.run(RELEASE);
motor1.run(RELEASE);
} //RELEASE IS COMMAND TO STOP MOTOR
}
}
nice works , where is the app ?
ReplyDelete