Last active
August 30, 2017 09:11
-
-
Save dmccreary/bc01799d0975eac9f5ae to your computer and use it in GitHub Desktop.
Arduino
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
// --------------------------------------------------------------------------- Motors | |
// These are the pins to the the motor drive chip for the left wheel | |
int motor_left[] = {12, 13}; | |
// These are the pins to the the motor drive chip for the right wheel | |
int motor_right[] = {6, 7}; | |
// --------------------------------------------------------------------------- Setup | |
void setup() { | |
Serial.begin(9600); | |
// Setup motors | |
int i; | |
for(i = 0; i < 2; i++){ | |
pinMode(motor_left[i], OUTPUT); | |
pinMode(motor_right[i], OUTPUT); | |
} | |
} | |
// --------------------------------------------------------------------------- Loop | |
void loop() { | |
drive_forward(); | |
delay(1000); | |
motor_stop(); | |
Serial.println("1"); | |
drive_backward(); | |
delay(1000); | |
motor_stop(); | |
Serial.println("2"); | |
turn_left(); | |
delay(1000); | |
motor_stop(); | |
Serial.println("3"); | |
turn_right(); | |
delay(1000); | |
motor_stop(); | |
Serial.println("4"); | |
motor_stop(); | |
delay(1000); | |
motor_stop(); | |
Serial.println("5"); | |
} | |
// --------------------------------------------------------------------------- Drive | |
void motor_stop(){ | |
digitalWrite(motor_left[0], LOW); | |
digitalWrite(motor_left[1], LOW); | |
digitalWrite(motor_right[0], LOW); | |
digitalWrite(motor_right[1], LOW); | |
delay(25); | |
} | |
void drive_forward(){ | |
digitalWrite(motor_left[0], HIGH); | |
digitalWrite(motor_left[1], LOW); | |
digitalWrite(motor_right[0], HIGH); | |
digitalWrite(motor_right[1], LOW); | |
} | |
void drive_backward(){ | |
digitalWrite(motor_left[0], LOW); | |
digitalWrite(motor_left[1], HIGH); | |
digitalWrite(motor_right[0], LOW); | |
digitalWrite(motor_right[1], HIGH); | |
} | |
void turn_left(){ | |
digitalWrite(motor_left[0], LOW); | |
digitalWrite(motor_left[1], HIGH); | |
digitalWrite(motor_right[0], HIGH); | |
digitalWrite(motor_right[1], LOW); | |
} | |
void turn_right(){ | |
digitalWrite(motor_left[0], HIGH); | |
digitalWrite(motor_left[1], LOW); | |
digitalWrite(motor_right[0], LOW); | |
digitalWrite(motor_right[1], HIGH); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment