Push button + blink LED using ROS on Odroid-C1 and 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, 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 the same for Odroid also.

Figure 26 : LED + button in Raspberry Pi 2

The code for interfacing 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" ...

Get ROS Programming: Building Powerful Robots now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.