hello friends,
i have the following code with me. i am planning to control the DC brushed motors using a RC Receiver (FrSky).
The hardware is actually a unbranded 20A DC Motor Driver (attaching image of the hardware...) integrated with Arduino and is reading inputs from the RC Receiver on PIN 6 and PIN 7.
PIN 6 being Forward & Reverse (Channel 2 in RC Receiver)
and
PIN 7 being Left & Right (Channel 1 in RC Receiver)
int RightMotor = 9; // pin maping according to schematics
int LeftMotor = 10;
int R_dir = 8;
int L_dir = 12;
void setup() {
TCCR1B = TCCR1B & 0B11111000 | 0B00000100; // reducing the pwm freq
pinMode(RightMotor,OUTPUT);
pinMode(LeftMotor,OUTPUT);
pinMode(R_dir,OUTPUT);
pinMode(L_dir,OUTPUT);
}
void loop() {
Forward(255);
}
void Forward(unsigned int Pwm)
{
digitalWrite(R_dir,HIGH);
digitalWrite(L_dir,HIGH);
analogWrite(RightMotor,Pwm);
analogWrite(LeftMotor,Pwm);
}
void Backward(unsigned int Pwm)
{
digitalWrite(R_dir,HIGH);
digitalWrite(L_dir,HIGH);
analogWrite(RightMotor,Pwm);
analogWrite(LeftMotor,Pwm);
}
void Left(unsigned int Pwm)
{
digitalWrite(R_dir,LOW);
digitalWrite(L_dir,HIGH);
analogWrite(RightMotor,Pwm);
analogWrite(LeftMotor,Pwm);
}
void Right(unsigned int Pwm)
{
digitalWrite(R_dir,HIGH);
digitalWrite(L_dir,LOW);
analogWrite(RightMotor,Pwm);
analogWrite(LeftMotor,Pwm);
}
void Stop()
{
digitalWrite(RightMotor,LOW);
digitalWrite(LeftMotor,LOW);
}
thanking in advance for the help.