March 2019
Intermediate to advanced
312 pages
7h 37m
English
Now that we have understood the H-bridge circuit, we will write a program called Forward.cpp to move our robot forward. After that, we will write a program to move the robot backward, left, and right, and then stop. You can download the Forward.cpp program from Chapter03 of the GitHub repository.
The program for moving the robot forward is as follows:
#include <stdio.h>#include <wiringPi.h>int main(void){wiringPiSetup();pinMode(0,OUTPUT); pinMode(2,OUTPUT); pinMode(3,OUTPUT);pinMode(4,OUTPUT); for(int i=0; i<1;i++) {digitalWrite(0,HIGH); //PIN O & 2 will move the Left MotordigitalWrite(2,LOW);digitalWrite(3,HIGH); //PIN 3 & 4 will move the Right MotordigitalWrite(4,LOW);delay(3000); }return 0; }
Let's see how this program ...