Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int mot1 = 8;
- int mot2 = 9;
- int en1 = 10;
- int dir = 6;
- bool state = true;
- int nob = A0;
- int val=0;
- void setup()
- {
- pinMode(mot1,OUTPUT);
- pinMode(mot2,OUTPUT);
- pinMode(en1,OUTPUT);
- pinMode(dir,INPUT_PULLUP);
- }
- void loop()
- {
- val = analogRead(nob);
- analogWrite(en1, val / 4);
- if(digitalRead(dir)==LOW)
- {
- state=!state;
- while(dir==LOW);
- delay(300);
- }
- if(state)
- {
- digitalWrite(mot1,HIGH);
- digitalWrite(mot2,LOW);
- }
- else
- {
- digitalWrite(mot1,LOW);
- digitalWrite(mot2,HIGH);
- }
- }
Add Comment
Please, Sign In to add comment