I got my program to work with a couple of buttons to drive two separate motors forward and backwards. So in total, 4 separate buttons. I used "serial.println()" to verify the buttons being pressed. Tested it and it worked the way I like.
When I tell motor A to move forward, I can simultaneously tell motor B to move backwards. It's all gravy until I remove the serial commands. Doing that, I can only do one command at a time, rather than simultaneously. Any inputs to why it's happening this way?
Code WITH serial commands and it works just fine with my microcontroller connected to my serial port. I also bolded the parts I took out with the code that sorta works:
#include <BMSerial.h>
#include <RoboClaw.h>#define address 0x80
RoboClaw roboclaw(8,9);
// Joypad Buttons
const int upA = 2;
const int downA = 3;
const int upB = 4;
const int downB = 5;void setup()
{
pinMode(upA, INPUT);
pinMode(downA, INPUT);
pinMode(upB, INPUT);
pinMode(downB, INPUT);digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);roboclaw.begin(2400);
Serial.begin(9600);
}void loop()
{if(digitalRead(upA) == LOW)
{
roboclaw.ForwardM1(address, 96);
Serial.println( F( "Up A" ) );
}if(digitalRead(downA) == LOW)
{
roboclaw.BackwardM1(address, 96);
Serial.println( F( "Down A" ) );
}if(digitalRead(upB) == LOW)
{
roboclaw.ForwardM2(address, 96);
Serial.println( F( "Up B" ) );
}if(digitalRead(downB) == LOW)
{
roboclaw.BackwardM2(address, 96);
Serial.println( F( "Down B" ) );
;
}if(digitalRead(upA) == HIGH && digitalRead(downA) == HIGH && digitalRead(upB) == HIGH && digitalRead(downB) == HIGH)
{
roboclaw.ForwardM1(address, 0);
roboclaw.ForwardM2(address, 0);
roboclaw.BackwardM1(address, 0);
roboclaw.BackwardM2(address, 0);
Serial.println( F( "0 Velocity" ) );
}}
Code WITHOUT serial commands:
#include <BMSerial.h>
#include <RoboClaw.h>
#define address 0x80
RoboClaw roboclaw(8,9);
// Joypad Buttons
const int upA = 2;
const int downA = 3;
const int upB = 4;
const int downB = 5;
void setup()
{
pinMode(upA, INPUT);
pinMode(downA, INPUT);
pinMode(upB, INPUT);
pinMode(downB, INPUT);
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
roboclaw.begin(2400);
}
void loop()
{
if(digitalRead(upA) == LOW)
{
roboclaw.ForwardM1(address, 96);
}
if(digitalRead(downA) == LOW)
{
roboclaw.BackwardM1(address, 96);
}
if(digitalRead(upB) == LOW)
{
roboclaw.ForwardM2(address, 96);
}
if(digitalRead(downB) == LOW)
{
roboclaw.BackwardM2(address, 96);
;
}
if(digitalRead(upA) == HIGH && digitalRead(downA) == HIGH && digitalRead(upB) == HIGH && digitalRead(downB) == HIGH)
{
roboclaw.ForwardM1(address, 0);
roboclaw.ForwardM2(address, 0);
roboclaw.BackwardM1(address, 0);
roboclaw.BackwardM2(address, 0);
}
}
EDIT: I checked again, the both code WORK "correctly" as long as my microcontroller's connected through the serial port.