I am just getting in to using an Arduino, and am starting off with a tank-tracked robot project.
I am using an Arduino UNO R3, with and Adafruit Motorshield V2. I have 12VDC supplied to the motor shield, and 9VDC supplied to the Arduino via barrel jack. I am using four 12V brushless motors, with hall sensors (have no idea how to utilize this), one motor to run each track (4 in total). My transmitter is a FlySky-I6X, receiver is FS-IA6B. The following code is what I have come up with based on quite a bit of searching online, with the expectations of having Channel 2 run the RIGHT track (2 motors), and Channel 3 run the LEFT track (2 motors). So far, there is no response in any way when powered up and connected to the transmitter. Any assistance with what might be the issue would be greatly appreciated.
#include <Wire.h>
#include <Adafruit_MotorShield.h>
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *LF = AFMS.getMotor(4); //Port M4
Adafruit_DCMotor *RF = AFMS.getMotor(3); //Port M3
Adafruit_DCMotor *LR = AFMS.getMotor(1); //Port M1
Adafruit_DCMotor *RR = AFMS.getMotor(2); //Port M2
int ch2,ch3,LEFT,RIGHT;
const int in1 = A2, in2 = A3;
void setup() {
Serial.begin(9600);
AFMS.begin();
pinMode(in1, INPUT);
pinMode(in2, INPUT);
LF->setSpeed(255);
LF->run(RELEASE);
RF->setSpeed(255);
RF->run(RELEASE);
LR->setSpeed(255);
LR->run(RELEASE);
RR->setSpeed(255);
RR->run(RELEASE);
}
void loop() {
ch2 = pulseIn(in1, HIGH, 35000);
ch2 = pulseIn(in1, LOW, 35000);
ch3 = pulseIn(in2, HIGH, 35000);
ch3 = pulseIn(in2, LOW, 35000);
if(ch2 != 0 || ch3 != 0){{
ch2 = constrain(ch2, 1010, 1985);
ch3 = constrain(ch3, 1010, 1985);
ch2 = map(ch2, 1010, 1985, 490, -485);
ch3 = map(ch3, 1010, 1985, 490, -485);
}
LEFT = ch3;
RIGHT = ch2;
LEFT = constrain(LEFT, -100, 100);
RIGHT = constrain(RIGHT, -100, 100);
if(LEFT >= 1550){
LF->setSpeed(map(LEFT, 1550, 1985, 0, 255));
LF->run(FORWARD);
LR->setSpeed(map(LEFT, 1550, 1985, 0, 255));
LR->run(FORWARD);
}
else if(LEFT <= 1450){
LF->run(BACKWARD);
LR->run(BACKWARD);
LR->setSpeed(map(LEFT, 1450, 1010, 0, 255));
LF->setSpeed(map(LEFT, 1450, 1010, 0, 255));
}
else{
LF->run(RELEASE);
LR->run(RELEASE);
}
if(RIGHT >= 1550){
RF->run(FORWARD);
RR->run(FORWARD);
RR->setSpeed(map(RIGHT, 1550, 1985, 0, 255));
RF->setSpeed(map(RIGHT, 1550, 1985, 0, 255));
}
else if(RIGHT <= 1450){
RF->run(BACKWARD);
RR->run(BACKWARD);
RR->setSpeed(map(RIGHT, 1450, 1010, 0, 255));
RF->setSpeed(map(RIGHT, 1450, 1010, 0, 255));
}
else{
RF->run(RELEASE);
RR->run(RELEASE);
LF->run(RELEASE);
LR->run(RELEASE);
}
}
}