I've assembled the TI RSLK Robot Maze Edition for a final project for my embedded systems class. Instead of using the MSP432P401R LaunchPad that came with the kit to control the power board, I've used an Arduino MEGA 2560 instead. I'm also using a KY-023 Analog Joystick to control the two dc motors.
The challenge that I'm having now is how do I write my code to reverse the motors in the opposite direction so the RSLK can move backwards?
Here's my code
int xPin = A0; // analog input for x-axis joystick
int yPin = A1; // analog input for y-axis joystick
int yPosition = 0;
int xPosition = 0;
//Right motor pins
#define MRSpeed 11
#define MRDir 10
#define MRSleep 9
//Left motor pins
#define MLSpeed 8
#define MLDir 7
#define MLSleep 6
void setup() {
Serial.begin(9600);
pinMode(xPin, INPUT); // setup x input
pinMode(yPin, INPUT); // setup y input
pinMode(MRSpeed, OUTPUT);
pinMode(MRDir, OUTPUT);
pinMode(MRSleep, OUTPUT);
digitalWrite(MRSleep, 1);
pinMode(MLSpeed, OUTPUT);
pinMode(MLDir, OUTPUT);
pinMode(MLSleep, OUTPUT);
digitalWrite(MLSleep, 1);
}
void loop() {
yPosition = analogRead(yPin);
xPosition = analogRead(xPin);
//Steer Forward
if (yPosition > 1020)
{
analogWrite(MRSpeed, 255); //To move right wheel forward
analogWrite(MLSpeed, 255); //To move left wheel forward
}
//To stop both wheels
else if (yPosition = 506 || 505)
{
analogWrite(MRSpeed, 0);
analogWrite(MLSpeed,0);
}
//Turn Right
if(xPosition < 512)
{
analogWrite(MRSpeed, 0);
analogWrite(MLSpeed, 255);
}
//Turn Left
if(xPosition > 1020)
{
analogWrite(MRSpeed, 255);
analogWrite(MLSpeed, 0);
}
}
As you can see I was able to build my code to make it move forward, right, and left.