Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

<< Results, Conclusion, and Further Work

...

 Arduino Code (C++):

#include "DualMC33926MotorShield.h"
DualMC33926MotorShield md;

int i=0;
int switchPin = 13; //pin for the button
int ledPin = 2;
int reading = LOW;
int lastButtonState = LOW;
int buttonState;
int count;
int everything = 0;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 200; //grace period for button press to avoid false positives

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

void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Dual MC33926 Motor Shield");
md.init();
md.setM1Speed(0);
pinMode(switchPin,INPUT);
}

void loop() {
// put your main code here, to run repeatedly:
reading = digitalRead(switchPin);
if ((millis() - lastDebounceTime) >= debounceDelay && reading == LOW) {
count++;
digitalWrite(ledPin, HIGH);
everything = 1;
lastDebounceTime = millis();
}
else
{everything = 0;}

if (everything == 1)
{
for (i = 0; i<000; i++)
{
md.setM1Speed(50);
delay(1);
stopIfFault();
}

delay(5);

for (i = 0; i<1000; i++)
{
md.setM1Speed(-50);
delay(1);
stopIfFault();
}

}
everything =0;
md.setM1Speed(0);
}

>> Citations