Hey ive ordered my parts for my balancing bot, and ive written my initial code to get the motors working, ive posted the code below, not sure if it will work so any help is appreciated to help me get the motors running. Since i dont have my motors or driver yet im not sure if the code works since ive never worked with the library, so if anyone that has used it can check my code and give me any feedback it would help.
thanks
#include <DualVNH5019MotorShield.h>
//Pin Map
int MINA1 = 2; // Motor 1 direction input A
int MINB1 = 4; // Motor 1 direction input B
int M1ENDIAG1 = 6; // Motor 1 enable input/fault output
int M1CS = A0; // Motor 1 current sense output
int MINA2 = 7; // Motor 2 direction input A
int MINB2 = 8; // Motor 2 direction input B
int M2ENDIAG2 = A2;
int M2CS = A1;
void setup()
{
pinMode(MINA1, OUTPUT); // Motor 1 forward
pinMode(MINB1, OUTPUT); // Motor 1 reverse
pinMode(MINA2, OUTPUT); // Motor 2 forward
pinMode(MINB2, OUTPUT); // Motor 2 reverse
}
void loop()
{
delay(4000);
for(int speedvalue = 0 ; speedvalue <= 255; speedvalue +=10) {
analogWrite(MINA1, speedvalue); // Motor 1 and 2 forward from zero to full speed at +10 increments
analogWrite(MINA2, speedvalue);
delay(6000);
for(int speedvalue = 255 ; speedvalue >= 0; speedvalue -=10) {
analogWrite(MINA1, speedvalue); // Motor 1 and 2 back to zero from full speed.
analogWrite(MINA2, speedvalue);
delay(6000);
}
}
for(int speedvalue = 0 ; speedvalue <= 255; speedvalue +=10) {
analogWrite(MINB1, speedvalue);
analogWrite(MINB2, speedvalue);
delay(6000);
for(int speedvalue = 255 ; speedvalue >= 0; speedvalue -=10)
analogWrite(MINB1, speedvalue);
analogWrite(MINB2, speedvalue);
delay(6000);
}
}
what i was hoping to achieve with this code was to get the motors going forward full speed from zero, back to zero, and reverse full speed, back to zero.