Created
December 8, 2015 15:23
-
-
Save tgolsson/3a6c185ec35eead06bcc to your computer and use it in GitHub Desktop.
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
const int ENCODER_PIN_L = 0, | |
ENCODER_PIN_R = 1; | |
//this struct holds the pin numbers for the motor shield | |
struct MotorShieldPins { | |
int DIR_; //direction pin | |
int PWM_; //pwm pin | |
int BRK_; //brake pin | |
int CUR_; //current sensor | |
MotorShieldPins(int DIR, int BRK, int PWM_pin, int CUR) : DIR_(DIR), BRK_(BRK), PWM_(PWM_pin), CUR_(CUR) {}; | |
}; | |
void initMotor(MotorShieldPins* pins); | |
MotorShieldPins * mspLeft, * mspRight; | |
void setup() { | |
mspLeft = new MotorShieldPins(2, 9, 3, A0); | |
mspRight = new MotorShieldPins(5, 8, 6, A1); | |
// put your setup code here, to run once: | |
analogWriteResolution(12); | |
analogReadResolution(12); | |
initMotor(mspLeft); | |
initMotor(mspRight); | |
pinMode(ENCODER_PIN_L,INPUT); | |
pinMode(ENCODER_PIN_R,INPUT); | |
digitalWrite(ENCODER_PIN_L,HIGH); // pull-up | |
digitalWrite(ENCODER_PIN_R,HIGH); // pull-up | |
analogWrite(mspLeft->PWM_,4095); | |
analogWrite(mspRight->PWM_,4095); | |
} | |
void initMotor(MotorShieldPins* pins) | |
{ | |
pinMode(pins->DIR_,OUTPUT); | |
pinMode(pins->BRK_,OUTPUT); | |
pinMode(pins->PWM_,OUTPUT); | |
pinMode(pins->CUR_,INPUT); | |
digitalWrite(pins->DIR_,HIGH); | |
digitalWrite(pins->BRK_,LOW); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment