I hadn’t realised that “i” was a variable (arduino beginner!), therefore i’ve changed “i” to ManualSpeedVal which works to an extent, however the motor runs slower than it does when “auto raise” is pressed.
I have a feeling this is since “ManualSpeedVal” is declared twice?
(Code pasted as text to highlight relevant parts)
#include “DualVNH5019MotorShield.h”
DualVNH5019MotorShield md;
const int AutoRaise = 53;
const int Stop = 23;
const int ManualRaise = 50;
int buttonTrigger = 0;
int ManualSpeedVal = 0;
void setup(){
Serial.begin(115200);
pinMode(AutoRaise, INPUT);
pinMode(Stop, INPUT);
pinMode(ManualRaise, INPUT);
md.init();
}
void stopIfFault()
{
if (md.getM1Fault())
{
Serial.println(“M1 fault”);
while(1);
}
if (md.getM2Fault())
{
Serial.println(“M2 fault”);
while(1);
}
}
void loop(){
///////////////AUTO-RAISE///////////////////
// if the auto raise button is pressed
if(digitalRead(AutoRaise) == HIGH){
for (int i = 0; i <= 400; i++)
{
// turn on the motor
md.setM1Speed(i);
stopIfFault();
// set the button trigger variable to 1
buttonTrigger = 1;
}
}
/////////////////STOP//////////////////////
// if the stop button is pressed
if(digitalRead(Stop) == HIGH){
// turn off the motor
md.setM1Speed(0);
// and set the button trigger variable to 2
buttonTrigger = 2;
}
////////////////MANUAL-RAISE////////////////
// if the manual raise button is pressed,
if(digitalRead(ManualRaise) == HIGH){
// then check motor state. if already turning then do nothing
if(ManualSpeedVal > 0){
}
// otherwise if motor is not on
else{
for (int ManualSpeedVal = 0; ManualSpeedVal <= 400; ManualSpeedVal++)
{
// turn it on
md.setM1Speed(ManualSpeedVal);
}
// and set the button Trigger to 3
buttonTrigger = 3;
}
}
// if the manual raise button is now not pressed, i.e. released.
else{
// but the motor was turned on by the manual raise button
if(buttonTrigger == 3){
// then turn off the motor.
md.setM1Speed(0);
}
}
}