Skip to content

Instantly share code, notes, and snippets.

@RobolinkAkademi
Created August 26, 2020 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RobolinkAkademi/4d0f7f5347c0bb6ae81d4b3887bd597b to your computer and use it in GitHub Desktop.
Save RobolinkAkademi/4d0f7f5347c0bb6ae81d4b3887bd597b to your computer and use it in GitHub Desktop.
#define enA 9
#define in1 6
#define in2 7
#define button 4
int rotDirection = 0;
int pressed = false;
void setup() {
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(button, INPUT);
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
}
void loop() {
int potValue = analogRead(A0);
int pwmOutput = map(potValue, 0, 1023, 0 , 255);
analogWrite(enA, pwmOutput);
if (digitalRead(button) == true) {
pressed = !pressed;
}
while (digitalRead(button) == true);
delay(20);
if (pressed == true & rotDirection == 0) {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
rotDirection = 1;
delay(20);
}
if (pressed == false & rotDirection == 1) {
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
rotDirection = 0;
delay(20);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment