Created
March 23, 2017 21:26
-
-
Save jesu0404/7bdaa592d9c5f798a7664479dc57b9ab to your computer and use it in GitHub Desktop.
Uses a switch to turn a DC motor on and off
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 switchPin = 2; | |
const int motor1Pin = 3; | |
const int motor2Pin = 4; | |
const int enablePin = 9; | |
void setup() { | |
pinMode(switchPin, INPUT); | |
pinMode(motor1Pin, OUTPUT); | |
pinMode(motor2Pin, OUTPUT); | |
pinMode(enablePin, OUTPUT); | |
analogWrite(enablePin, 100); | |
} | |
void loop() { | |
int switchVal = digitalRead(switchPin); | |
if(switchVal == HIGH) { | |
digitalWrite(motor1Pin, HIGH); | |
digitalWrite(motor2Pin, LOW); | |
} | |
else { | |
digitalWrite(motor1Pin, LOW); | |
digitalWrite(motor2Pin, LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment