Created
June 9, 2016 07:23
-
-
Save monpetit/d1a8395a5cc5905e36412bda990cf5e0 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
| int enablePin = 11; | |
| int in1Pin = 10; | |
| int in2Pin = 9; | |
| boolean dir = false; | |
| int speed = 255; | |
| void setup() | |
| { | |
| pinMode(in1Pin, OUTPUT); | |
| pinMode(in2Pin, OUTPUT); | |
| pinMode(enablePin, OUTPUT); | |
| } | |
| void loop() | |
| { | |
| dir = ! dir; | |
| setMotor(speed, dir); | |
| delay(5000); | |
| } | |
| void setMotor(int speed, boolean direct) | |
| { | |
| analogWrite(enablePin, speed); | |
| digitalWrite(in1Pin, ! direct); | |
| digitalWrite(in2Pin, direct); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment