I have a Arduino Uno and your Driver Dual Shield stacked with a pot connected on Ao
I’m using code below to turn on the motor when Newvalue is less than Prevalue. Using the serial monitor to send New values that would be either larger or smaller turning the motor on or off.
Driver gets locked in either on or off state, when next New value is sent using the monitor, am I missing something in the code.
Looking forward
#include "DualVNH5019MotorShield.h"
DualVNH5019MotorShield md;
int sensorPin = A0; // select the input pin for the potentiometer
int sensorValue = 0; // variable to store the value coming from the sensor
int j1;
int j2;
int PreVal;
int NewVal; // New Actuator Value
int NewVal1; // New Actuator Value Thousandth
int NewVal2; // New Actuator Value Hundredth
int NewVal3; // New Actuator Value Tenth
int NewVal4; // New Actuator Value 0nes
int NewVal5; // New Actuator Value
int NewVal6; // New Actuator Value
int potPin = 0; // select the input pin for the potentiometer
void setup()
{
Serial.begin(115200);
Serial.println("Dual VNH5019 Motor Shield");
md.init();
}
void loop()
{
if (Serial.available() > 0) {
j1 = Serial.read();
if (j1 == 'A'){ // Find by reading the New X Value pre curser A
delay (11); // It seems to need a delay here
NewVal = int (Serial.read()); // Read NewX value character
Serial.println(NewVal); // Prit NewX value character
NewVal1 = int (Serial.read()-48);//Read NewX1 value character convert to integer
NewVal2 = int (Serial.read()-48);//Read NewX2 value character convert to integer
NewVal3 = int (Serial.read()-48);//Read NewX3 value character convert to integer
NewVal4 = int (Serial.read()-48);//Read NewX4 value character convert to integer
Serial.println(NewVal1); //Print NewX1 digit integer
Serial.println(NewVal2); //Print NewX2 digit integer
Serial.println(NewVal3); //Print NewX3 digit integer
Serial.println(NewVal4); //Print NewX4 digit integer
NewVal = ((NewVal1*1000)+(NewVal2*100)+(NewVal3*10)+(NewVal4*1)); // Add NewX digits
PreVal = analogRead(potPin); // Read actuator pot value OldX
Serial.println(PreVal); // Print actuator pot value OldX
Serial.println(NewVal); // Print actuator pot value OldX
Serial.println("check1");
if (NewVal << PreVal)
{
delay(2);
Serial.println("Forward");
md.setM1Speed(200);
delay(2000);
Serial.println("Stop");
md.setM1Speed(0);
delay(2000);
}
}
}
}