Last active
October 16, 2018 05:44
-
-
Save ThomasLengeling/60e3a4de5d50b98010f62cc7f0885e9f to your computer and use it in GitHub Desktop.
TD Motor tester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Motor Driver | |
* https://www.pololu.com/product/2990 | |
*/ | |
int i = 0; | |
int limit = 5 * 60 * 5 ; | |
int PWPHASE = 5; | |
int DGIOENABLE = 4; | |
int ANSLEEP = 6; | |
int numHits = 8 * 3; | |
int numHitsCount = 0; | |
int numWaitCout = 0; | |
unsigned long prevTimeCC = 0L; | |
unsigned long prevTimeHIT = 0L; | |
int eventPULLHIT = 1 ; | |
bool enablePULLHIT = false; | |
void setup() { | |
// put your setup code here, to run once: | |
//pinMode(9, OUTPUT); | |
pinMode(DGIOENABLE, OUTPUT); | |
prevTimeHIT = millis(); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
unsigned long cTime = millis(); | |
//HIT | |
if (eventPULLHIT == 1) { | |
if ( abs(cTime - prevTimeHIT) >= 120) { | |
analogWrite(PWPHASE, 255); | |
digitalWrite(DGIOENABLE, HIGH); | |
analogWrite(ANSLEEP, 255); | |
prevTimeHIT = cTime; | |
eventPULLHIT = 2; | |
} | |
} | |
//BACK | |
if (eventPULLHIT == 2) { | |
if ( abs(cTime - prevTimeHIT) >= 50) { | |
// analogWrite(PWPHASE, 0); | |
//digitalWrite(DGIOENABLE, HIGH); | |
//analogWrite(ANSLEEP, 255); | |
analogWrite(ANSLEEP, 0); | |
prevTimeHIT = cTime; | |
eventPULLHIT = 3; | |
} | |
} | |
//WAIT | |
if ( eventPULLHIT == 3) { | |
if ( abs(cTime - prevTimeHIT) >= 50) { | |
prevTimeHIT = cTime; | |
//analogWrite(PWPHASE, 0); | |
//digitalWrite(DGIOENABLE, LOW); | |
analogWrite(ANSLEEP, 0); | |
eventPULLHIT = 1; | |
numHitsCount++; | |
if (numHitsCount >= numHits) { | |
eventPULLHIT = 4; | |
numWaitCout = 0; | |
numHitsCount = 0; | |
} | |
} | |
} | |
//WAIT | |
if (eventPULLHIT == 4) { | |
if ( abs(cTime - prevTimeHIT) >= 10000) { | |
prevTimeHIT = cTime; | |
numWaitCout = 0; | |
eventPULLHIT = 1; | |
} | |
} | |
/* | |
// short circuit | |
if ( abs(cTime - prevTimeCC) >= 1000 * 5 ) { | |
analogWrite(PWMPIN, 0); | |
digitalWrite(DGIOPIN, LOW); | |
prevTimeCC = cTime; | |
} | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment