SHARE
TWEET

Untitled

a guest Nov 18th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    
  2. #include <Arduino.h>
  3. #define ENB 5
  4. #define IN1 7
  5. #define IN2 8
  6. #define IN3 9
  7. #define IN4 11
  8. #define ENA 6
  9. #define LT_R !digitalRead(10)
  10. #define LT_M !digitalRead(4)
  11. #define LT_L !digitalRead(2)
  12.  
  13. void forward(){
  14.     digitalWrite(ENA, HIGH);
  15.     digitalWrite(ENB, HIGH);    
  16.     digitalWrite(IN1, HIGH);    
  17.     digitalWrite(IN2, LOW);    
  18.     digitalWrite(IN3, LOW);    
  19.     digitalWrite(IN4, HIGH);
  20.     Serial.println("forward");
  21. }
  22.  
  23. void back(){
  24.     digitalWrite(ENA, HIGH);
  25.     digitalWrite(ENB, HIGH);    
  26.     digitalWrite(IN1, LOW);    
  27.     digitalWrite(IN2, HIGH);    
  28.     digitalWrite(IN3, HIGH);    
  29.     digitalWrite(IN4, LOW);
  30.     Serial.println("back");
  31. }
  32.  
  33. void left(){
  34.     digitalWrite(ENA, HIGH);
  35.     digitalWrite(ENB, HIGH);    
  36.     digitalWrite(IN1, LOW);    
  37.     digitalWrite(IN2, HIGH);    
  38.     digitalWrite(IN3, LOW);    
  39.     digitalWrite(IN4, HIGH);
  40.     Serial.println("left");
  41. }
  42.  
  43. void right(){
  44.     digitalWrite(ENA, HIGH);
  45.     digitalWrite(ENB, HIGH);    
  46.     digitalWrite(IN1, HIGH);    
  47.     digitalWrite(IN2, LOW);    
  48.     digitalWrite(IN3, HIGH);    
  49.     digitalWrite(IN4, LOW);
  50.     Serial.println("right");
  51. }
  52. void stop(){
  53.     digitalWrite(ENA, HIGH);
  54.     digitalWrite(ENB, HIGH);    
  55.     digitalWrite(IN1, LOW);    
  56.     digitalWrite(IN2, LOW);    
  57.     digitalWrite(IN3, LOW);    
  58.     digitalWrite(IN4, LOW);
  59.     Serial.println("stop");
  60. }
  61.  
  62. void setup(){
  63.     Serial.begin(9600);
  64.     pinMode(IN1, OUTPUT);
  65.     pinMode(IN2, OUTPUT);
  66.     pinMode(IN3, OUTPUT);
  67.     pinMode(IN4, OUTPUT);
  68.     pinMode(ENB, OUTPUT);
  69.     pinMode(ENA, OUTPUT);
  70.     digitalWrite(ENB, HIGH);
  71. }
  72.  
  73. void loop(){
  74.    if(LT_R == 0 or LT_M ==0 or LT_L ==0){
  75.        forward();
  76.    }
  77.     if(LT_R == 1 or LT_M ==1 or LT_L ==1){
  78.         back();
  79.         delay(1500);
  80.         left();
  81.         delay(1000);
  82.         }
  83. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top