Guest User

Untitled

a guest
Jan 17th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. int mot1 = 8;
  2. int mot2 = 9;
  3. int en1 = 10;
  4. int dir = 6;
  5. bool state = true;
  6. int nob = A0;
  7. int val=0;
  8.  
  9.  
  10.  
  11. void setup()
  12. {
  13. pinMode(mot1,OUTPUT);
  14. pinMode(mot2,OUTPUT);
  15. pinMode(en1,OUTPUT);
  16. pinMode(dir,INPUT_PULLUP);
  17.  
  18. }
  19.  
  20. void loop()
  21. {
  22.  
  23. val = analogRead(nob);
  24.  
  25. analogWrite(en1, val / 4);
  26.  
  27. if(digitalRead(dir)==LOW)
  28. {
  29. state=!state;
  30. while(dir==LOW);
  31. delay(300);
  32. }
  33. if(state)
  34. {
  35. digitalWrite(mot1,HIGH);
  36. digitalWrite(mot2,LOW);
  37. }
  38. else
  39. {
  40. digitalWrite(mot1,LOW);
  41. digitalWrite(mot2,HIGH);
  42. }
  43.  
  44.  
  45. }
Add Comment
Please, Sign In to add comment