Blink the LED

Seems like it is time for you to start learning Linguino! The easiest way is to start with Blink the LED example. In this example we will guide you through the necessary steps to create your first Arduino program using Linguino.

In the following example you will dive into XML (eXtended Markup Language) to build your first Arduino program. Nonetheless, is not mandatory to know XML at all! In fact to build Linguino programs you may not have any programming skills at all.

Agents

The most basic and important Linguino property is the Agent. Agents may be seen as a the program itself, since all properties declared inside the XML's Agent tag, will live inside an Arduino board.
To start developing agents go to your project folder src/agents and create your first agent. You may call it blink_led_agent.xml.

<agent>
  <name>blinkLedAgent</name>
</agent>

The property name in the example above is the only mandatory for agents. This identify the agent in a much bigger system, with multiple Arduinos (right now we are not going on that detail).

Modules

Modules are where your code "lives". You can imagine your program as a set of little blocks, executed sequently. Every of these blocks are your modules.
Inside modules you can define both name and function (...for now!). The name works as the agent's name: to identify the module inside agent (and inside a bigger system). The function defines what is to be executed by the module.
Lets keep to our example and blink a LED! To do this, we will actually need two modules to turn on and then off a LED, using two Linguino's built-in functions: digitalLow and digitalHigh

<agent>
  <name>blinkLedAgent</name>

  <module>
    <name>turnLedOn</name>
    <function>std::digitalHigh(13)</function>
  </module>

  <module>
    <name>turnLedOff</name>
    <function>std::digitalLow(13)</function>
  </module>
</agent>

The std:: and (13) in the example, are not typos! What those mean is that:

  • first, we are using functions from the Linguino's standard package (std), that is built-in functions;
  • and second, the functions can indeed receive a single parameter. In this case the pin that is connected to the LED that we are trying to blink. This parameter is explained in detail in Custom functions.

If you were to use the program above you wouldn't actually see the LED blink. This happens because the execution loop of Arduino is so fast that basically you wouldn't notice the changes in the LED.
To achieve these behavior, just add two more modules, one after each of the already defined, with the built-in sleep function.

<agent>
  <name>blinkLedAgent</name>

  <module>
    <name>turnLedOn</name>
    <function>std::digitalHigh(13)</function>
  </module>

  <module>
    <name>sleep1</name>
    <function>std::sleep(1000)</function>
  </module>

  <module>
    <name>turnLedOff</name>
    <function>std::digitalLow(13)</function>
  </module>

  <module>
    <name>sleep1</name>
    <function>std::sleep(1000)</function>
  </module>
</agent>

That's it! You wrote your first Linguino program. Yes, is that simple. Now we don't want to be stuck here with a program that does not run at all.

Hands on! Lets build, deploy and run this program on Build, deploy, run!

  1. Blink the LED
  2. Build, deploy, run!