Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Current »

<< 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<9000; i++)
{
md.setM1Speed(-50);
delay(1);
stopIfFault();
}
 
delay(5);
md.setM1Speed(0);
 
reading = digitalRead(switchPin);
while (reading == HIGH)
{
  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<8500; i++)
{
md.setM1Speed(50);
delay(1);
stopIfFault();
}
}
}
everything =0;
md.setM1Speed(0);
}

 

>> Citations

  • No labels