Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define Lpwm_pin 5 //pin of controlling speed---- ENA of motor driver board
- #define Rpwm_pin 6 //pin of controlling speed---- ENB of motor driver board
- int pinLB = 2; //pin of controlling turning---- IN1 of motor driver board
- int pinLF = 4; //pin of controlling turning---- IN2 of motor driver board
- int pinRB = 7; //pin of controlling turning---- IN3 of motor driver board
- int pinRF = 8; //pin of controlling turning---- IN4 of motor driver board
- #define enA 6
- #define in1 7
- #define in2 5
- #define enB 3
- #define in3 4
- #define in4 2
- struct {
- void go_backward(unsigned char speed_val) // speed_val:0~255
- {
- digitalWrite(pinRB, HIGH);
- digitalWrite(pinRF, LOW);
- digitalWrite(pinLB, HIGH);
- digitalWrite(pinLF, LOW);
- analogWrite(Lpwm_pin, speed_val);
- analogWrite(Rpwm_pin, speed_val);
- }
- void go_forward(unsigned char speed_val) // speed_val:0~255
- {
- digitalWrite(pinRB, LOW);
- digitalWrite(pinRF, HIGH);
- digitalWrite(pinLB, LOW);
- digitalWrite(pinLF, HIGH);
- analogWrite(Lpwm_pin, speed_val);
- analogWrite(Rpwm_pin, speed_val);
- }
- void stay() //stop
- {
- analogWrite(Lpwm_pin, 0);
- analogWrite(Rpwm_pin, 0);
- }
- void turn_left() {
- digitalWrite(in1, HIGH);
- digitalWrite(in2, HIGH);
- digitalWrite(in3, HIGH);
- digitalWrite(in4, HIGH);
- }
- void right() {
- }
- } Robot;
- void setup() {
- pinMode(pinLB, OUTPUT); // /pin 2
- pinMode(pinLF, OUTPUT); // pin 4
- pinMode(pinRB, OUTPUT); // pin 7
- pinMode(pinRF, OUTPUT); // pin 8
- pinMode(Lpwm_pin, OUTPUT); // pin 5 (PWM)
- pinMode(Rpwm_pin, OUTPUT); // pin 6(PWM)
- }
- void loop() {
- Robot.go_forward(200);
- delay(5000);
- Robot.right();
- delay(6e4);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement