# SoftBank Robotics documentation What's new in NAOqi 2.8?

# Control the LEDs

<< return to C++ examples

The aim of this example is to show how to control NAO’s LEDs using a proxy to ALLeds module. This example will make a colored animation on all of NAO’s LEDs.

The whole example is available here: `leds.zip`

## Source file:

`ledsexample.cpp`

    /**
    * Copyright (c) 2011 Aldebaran Robotics. All Rights Reserved
    *
    * \file ledsexample.cpp
    * \brief Play with NAO's leds.
    *
    * A simple example showing how to use NAO's leds using ALLedsProxy.
    * This example launches a colorful animation on NAO's leds.
    * We use here a specialized proxy to the ALLeds module.
    */

    #include <iostream>
    #include <alerror/alerror.h>
    #include <alproxies/alledsproxy.h>

    int main(int argc, char* argv[]) {

      if(argc != 2)
      {
        std::cerr << "Wrong number of arguments!" << std::endl;
        std::cerr << "Usage: movehead NAO_IP" << std::endl;
        exit(2);
      }

      try {
        /** Create a ALLedsProxy to call the methods to deal with NAO's leds.
        * Arguments for the constructor are:
        * - IP adress of the robot
        * - port on which NAOqi is listening, by default 9559
        */
        AL::ALLedsProxy leds(argv[1], 9559);

        /** Set the duration of the animation. */
        float duration = 3.0f;
        /** Play a green / yellow / red animation on all of NAO's leds. */
        leds.rasta(duration);
      }
      catch (const AL::ALError& e) {
        std::cerr << "Caught exception: " << e.what() << std::endl;
        exit(1);
      }
      exit(0);
    }

## CMakeLists.txt:

The corresponding CMakeLists.txt file is the following:

`CMakeLists.txt`

    ##
    # Copyright (c) 2011 Aldebaran Robotics. All Rights Reserved.

    cmake_minimum_required(VERSION 2.6.4 FATAL_ERROR)
    # Give a name to the project.
    project(ledsexample)
    # This include enable you to use qibuild CMake framework
    find_package(qibuild)

    # Create an executable named ledsexample,
    # with the source file : ledsexample.cpp
    qi_create_bin(ledsexample ledsexample.cpp)

    # Tell CMake that movehead depends on ALCOMMON and ALPROXIES.
    # This will set the libraries to link movehead with,
    # the include paths, and so on
    qi_use_lib(ledsexample ALCOMMON ALPROXIES)

Glossary Site map Index Support Contact Legal Notices