Created
June 18, 2018 14:20
-
-
Save andysheen/fbbd06590fce0e8ecf9f3c54150e4be8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#include <TimerOne.h> | |
// Motor 1 | |
int delayDown = 6500; | |
int delayUp = 10000; | |
int dir1PinB = 6; | |
int dir2PinB = 5; | |
int speedPinB = 10; | |
int dir1PinA = 4; | |
int dir2PinA = 11; | |
int speedPinA = 9; // Needs to be a PWM pin to be able to control motor speed | |
void setup() { // Setup runs once per reset | |
Timer1.initialize(15); | |
// initialize serial communication @ 9600 baud: | |
Serial.begin(9600); | |
//Define L298N Dual H-Bridge Motor Controller Pins | |
pinMode(dir1PinA, OUTPUT); | |
pinMode(dir2PinA, OUTPUT); | |
// pinMode(speedPinA, OUTPUT); | |
pinMode(dir1PinB, OUTPUT); | |
pinMode(dir2PinB, OUTPUT); | |
// pinMode(speedPinB, OUTPUT); | |
setPosition(); | |
} | |
void loop() { | |
// Initialize the Serial interface: | |
Timer1.pwm(speedPinA, 880); | |
digitalWrite(dir1PinA, HIGH); | |
digitalWrite(dir2PinA, LOW); | |
Timer1.pwm(speedPinB, 850); | |
digitalWrite(dir1PinB, LOW); | |
digitalWrite(dir2PinB, HIGH); | |
delay(4500); | |
Timer1.pwm(speedPinA, 850); | |
digitalWrite(dir1PinA, LOW); | |
digitalWrite(dir2PinA, HIGH); | |
Timer1.pwm(speedPinB, 880); | |
digitalWrite(dir1PinB, HIGH); | |
digitalWrite(dir2PinB, LOW); | |
delay(delayDown); | |
delay(2000); | |
serialTest(); | |
} | |
void setPosition() { | |
//set wipers in correct position | |
Timer1.pwm(speedPinA, 1023); | |
digitalWrite(dir1PinA, LOW); | |
digitalWrite(dir2PinA, HIGH); | |
Timer1.pwm(speedPinB, 1023); | |
digitalWrite(dir1PinB, HIGH); | |
digitalWrite(dir2PinB, LOW); | |
delay(4000); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment