Advertisement
STANAANDREY

arduino tank basic move

Aug 2nd, 2022
1,066
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. #define Lpwm_pin 5 //pin of controlling speed---- ENA of motor driver board
  2. #define Rpwm_pin 6 //pin of controlling speed---- ENB of motor driver board
  3. int pinLB = 2; //pin of controlling turning---- IN1 of motor driver board
  4. int pinLF = 4; //pin of controlling turning---- IN2 of motor driver board
  5. int pinRB = 7; //pin of controlling turning---- IN3 of motor driver board
  6. int pinRF = 8; //pin of controlling turning---- IN4 of motor driver board
  7. #define enA 6
  8. #define in1 7
  9. #define in2 5
  10. #define enB 3
  11. #define in3 4
  12. #define in4 2
  13.  
  14. struct {
  15.   void go_backward(unsigned char speed_val) // speed_val:0~255
  16.   {
  17.     digitalWrite(pinRB, HIGH);
  18.     digitalWrite(pinRF, LOW);
  19.     digitalWrite(pinLB, HIGH);
  20.     digitalWrite(pinLF, LOW);
  21.     analogWrite(Lpwm_pin, speed_val);
  22.     analogWrite(Rpwm_pin, speed_val);
  23.   }
  24.  
  25.   void go_forward(unsigned char speed_val) // speed_val:0~255
  26.   {
  27.     digitalWrite(pinRB, LOW);
  28.     digitalWrite(pinRF, HIGH);
  29.     digitalWrite(pinLB, LOW);
  30.     digitalWrite(pinLF, HIGH);
  31.     analogWrite(Lpwm_pin, speed_val);
  32.     analogWrite(Rpwm_pin, speed_val);
  33.   }
  34.  
  35.   void stay() //stop
  36.   {
  37.     analogWrite(Lpwm_pin, 0);
  38.     analogWrite(Rpwm_pin, 0);
  39.   }
  40.  
  41.   void turn_left() {
  42.     digitalWrite(in1, HIGH);
  43.     digitalWrite(in2, HIGH);
  44.     digitalWrite(in3, HIGH);
  45.     digitalWrite(in4, HIGH);
  46.   }
  47.  
  48.   void right() {
  49.    
  50.   }
  51. } Robot;
  52.  
  53. void setup() {
  54.   pinMode(pinLB, OUTPUT); // /pin 2
  55.   pinMode(pinLF, OUTPUT); // pin 4
  56.   pinMode(pinRB, OUTPUT); // pin 7
  57.   pinMode(pinRF, OUTPUT); // pin 8
  58.   pinMode(Lpwm_pin, OUTPUT); // pin 5 (PWM)
  59.   pinMode(Rpwm_pin, OUTPUT); // pin 6(PWM)  
  60. }
  61.  
  62. void loop() {
  63.   Robot.go_forward(200);
  64.   delay(5000);
  65.   Robot.right();
  66.   delay(6e4);
  67. }
  68.  
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement