Skip to Content
Hands-On Robotics Programming with C++
book

Hands-On Robotics Programming with C++

by Dinesh Tavasalkar
March 2019
Intermediate to advanced
312 pages
7h 37m
English
Packt Publishing
Content preview from Hands-On Robotics Programming with C++

Moving the robot

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learn Robotics Programming

Learn Robotics Programming

Danny Staple
C++ Reactive Programming

C++ Reactive Programming

Praseed Pai, Peter Abraham

Publisher Resources

ISBN: 9781789139006Supplemental Content