Again, this common problem appears in my computer.
I use Arduino UNO.
When I upload my code (posted below), I face this problem.
I've tried some solutions, but the error still exists.
Plz teach me how to solve the problem. Very urgent.
The solutions I tried:
- check whether correct arduino model I choose
- unplug all ports on the UNO.
My code verities successfully and is as follow:
#include <AFMotor.h>
#include <MeetAndroid.h>
/* declare MeetAndroid so that you can call functions with it
Command is sent from android phone to arduino UNO*/
MeetAndroid meetAndroid;
AF_DCMotor motor1(1, MOTOR12_1KHZ); // Model: Arduino motor/stepper/servo control - How to use
AF_DCMotor motor2(4, MOTOR12_1KHZ);
int Power_Val = 0; //somethings related to arduino ;
void setup()
{
// use the baud rate your bluetooth module is configured to
// not all baud rates are working well, i.e. ATMEGA168 works best with 57600
Serial.begin(9600);
// register callback functions, which will be called when an associated event occurs.
meetAndroid.registerFunction(Forward, 'A');
meetAndroid.registerFunction(Backward, 'B');
meetAndroid.registerFunction(Left, 'C');
meetAndroid.registerFunction(Right, 'D');
meetAndroid.registerFunction(Stop, 'E');
meetAndroid.registerFunction(Power, 'F');
}
void loop()
{
meetAndroid.receive(); // you need to keep this in your loop() to receive events
}
/*
- execute the commends sent from phone
*/
void Stop(byte flag, byte numOfValues)
{
StopDrive();
}
void Forward(byte flag, byte numOfValues)
{
ForwardDrive();
}
void Backward(byte flag, byte numOfValues)
{
BackwardDrive();
}
void Left(byte flag, byte numOfValues)
{
LeftDrive();
}
void Right(byte flag, byte numOfValues)
{
RightDrive();
}
void Power(byte flag, byte numOfValues)
{
Power_Val = meetAndroid.getInt();
}
//Motor part
void MOTODRIVE(char motor,int speed,int dir)
{
if(motor == 'R')
{
motor1.setSpeed(Power_Val);
if(dir == 1)
{
motor1.run(BACKWARD);
}
else
{
motor1.run(FORWARD);
}
}
if(motor == 'L')
{
motor2.setSpeed(Power_Val);
if(dir == 1)
{
motor2.run(BACKWARD);
}
else
{
motor2.run(FORWARD);
}
}
}
void ForwardDrive()
{
MOTODRIVE('R',(Power_Val),0);
MOTODRIVE('L',(Power_Val),0);
}
void BackwardDrive()
{
MOTODRIVE('R',(Power_Val),1);
MOTODRIVE('L',(Power_Val),1);
}
void LeftDrive()
{
MOTODRIVE('R',0,0);
MOTODRIVE('L',0,0);
delay(50);
MOTODRIVE('L',(Power_Val),0);
}
void RightDrive()
{
MOTODRIVE('R',0,0);
MOTODRIVE('L',0,0);
delay(50);
MOTODRIVE('R',(Power_Val),0);
}
void StopDrive()
{
MOTODRIVE('R',0,0);
MOTODRIVE('L',0,0);
delay(50);
}