Skip to Content
Mastering ROS for Robotics Programming - Second Edition
book

Mastering ROS for Robotics Programming - Second Edition

by Lentin Joseph, Jonathan Cacace
February 2018
Beginner
580 pages
13h 20m
English
Packt Publishing
Content preview from Mastering ROS for Robotics Programming - Second Edition

Push button + blink LED using ROS on Raspberry Pi 2

The next example is handling input from a button. When we press the button, the code will publish to the led_blink topic and blink the LED. When the switch is off, the LED will also be OFF. The LED is connected to the 12th pin and GND, and the button is connected to the 11th pin and GND. The following image shows the circuit of this example. The circuit is also the same for Odroid:

Figure 26: LED + button in Raspberry Pi 2

The code for interfacing the LED and button is given next. The code can be saved with the name button.cpp inside the src folder:

#include "ros/ros.h" #include "std_msgs/Bool.h" ...
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

Mastering ROS for Robotics Programming - Third Edition

Mastering ROS for Robotics Programming - Third Edition

Lentin Joseph, Jonathan Cacace
Effective Robotics Programming with ROS - Third Edition

Effective Robotics Programming with ROS - Third Edition

Luis Sanchez, Enrique Fernandez Perdomo, Anil Mahtani

Publisher Resources

ISBN: 9781788478953Supplemental Content