~Arduino Code

We made a simple code with Arduino for turning on and off the machine.

#include "DualMC33926MotorShield.h"

DualMC33926MotorShield md;

// this constant won't change:
const int buttonPin =3; // the pin that the pushbutton is attached to

// Variables will change:
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
int m = -50; //adjust speed
int speed_motor = 0;

void stopIfFault()
{
if (md.getFault())
{
Serial.println("fault");
while(1);
}
}

void setup()
{
Serial.begin(115200);
Serial.println("Dual MC33926 Motor Shield");
pinMode(buttonPin, INPUT);
md.init();
}

void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// md speed controller
md.setM1Speed(speed_motor);
stopIfFault();

if (lastButtonState==LOW && buttonState==HIGH) {
speed_motor = 0;
lastButtonState = buttonState;
}
else {
if (lastButtonState==HIGH && buttonState==HIGH){
speed_motor = m;
lastButtonState = LOW;
}
else{
}
}
delay(50);
}