Skip to content

Instantly share code, notes, and snippets.

@elktros
Created September 20, 2016 16:59
Show Gist options
  • Save elktros/9fc6c751b2dd663135070c2d038f05e9 to your computer and use it in GitHub Desktop.
Save elktros/9fc6c751b2dd663135070c2d038f05e9 to your computer and use it in GitHub Desktop.
const int potPin = A0;
const int fwdbuttonPin = 13;
const int bckbuttonPin = 12;
const int pin1 = 11;
const int pin2 = 10;
int potValue = 0;
int motorValue = 0;
int fwdbuttonState = 0;
int bckbuttonState = 0;
void setup()
{
pinMode(fwdbuttonPin, INPUT_PULLUP);
pinMode(bckbuttonPin, INPUT_PULLUP);
pinMode (pin1, OUTPUT);
pinMode (pin2, OUTPUT);
}
void loop()
{
potValue = analogRead(potPin);
motorValue = map(potValue, 0, 1023, 0, 255);
fwdbuttonState = digitalRead(fwdbuttonPin);
bckbuttonState = digitalRead(bckbuttonPin);
if (fwdbuttonState == LOW)
{
analogWrite(pin1, motorValue);
digitalWrite (pin2, LOW);
}
else if (bckbuttonState == LOW)
{
analogWrite(pin2, motorValue);
digitalWrite (pin1, LOW);
}
else
{
digitalWrite (pin1, LOW);
digitalWrite (pin2, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment