Created
January 3, 2016 07:58
-
-
Save endeepak/5b3395c1be5597397fdc 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
| // Motor Code Adopted From: http://www.instructables.com/id/Control-your-motors-with-L293D-and-Arduino/?ALLSTEPS | |
| int motor_left[] = {2, 3}; | |
| int motor_right[] = {7, 8}; | |
| void setup() { | |
| for(int i = 0; i < 2; i++){ | |
| pinMode(motor_left[i], OUTPUT); | |
| pinMode(motor_right[i], OUTPUT); | |
| } | |
| } | |
| void loop() { | |
| delay(50); | |
| drive_forward(); // Change this line to other methods like drive_backward, turn_left, turn_right to test the rotation of wheels | |
| } | |
| 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); | |
| } | |
| void motor_stop(){ | |
| digitalWrite(motor_left[0], LOW); | |
| digitalWrite(motor_left[1], LOW); | |
| digitalWrite(motor_right[0], LOW); | |
| digitalWrite(motor_right[1], LOW); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment