• Download
  • Tutorials
  • Buy
  • Library
  • Docs
  • Forum
  • Log In

In Embrio, when you have 1 LED blinking, it's simple to make another LED blink. This tutorial introduces the concept of Functions in Embrio which let you encapsulate a group of nodes into a reusable node.

View Comments (0)

In this project I’ll blink 2 LEDs. In Embrio this is just as easy as blinking 1 led. I’ll start with the results of the Control LED Blink speed with Potentiometer, and just add another LED and potentiometer the same way. I plug this new LED into digital pin 5, and the new Potentiometer into pin A3.

I have the Blink LED Speed Control project opened in Embrio. I save a copy of the project and call it “Blink 2 LEDs Speed Control”. I already have the nodes set up to blink an LED and a potentiometer to control the speed, so I’m just going to make another copy for my new LED. Between the input and output nodes there are 4 nodes. I don’t want to have a copy of all 4 of these nodes, so first I’m going to turn these nodes into a function. I select all 4 of these nodes, leaving out the input and output node, by holding down the Shift key and either clicking each node, or dragging a box around them. I cut these nodes by using the right click menu or pressing Control X. In the tree view, I right click on the Agents folder and select New Function. A new blank node screen opens up. I paste the nodes onto it by pressing Control V or using the right click menu. I also rename the function to Speed Controlled Blink, by either right clicking on it in the tree and selecting Rename, or by middle clicking on it.

  • A - Functions show up in the tree view with a blue icon. All of the nodes in a function are copied and encapsulated by another node when the function is dragged onto a node screen.

  • B - By clicking the "make external" button, this input and output can be attached to from outside the function.

  • C - When done making changes to a function, click the "Save and Update Function Instances" button update the inputs and outputs on nodes in the project that encapsulate this function. To cancel your changes press the "Clear Changes" button.

I go back to my agent and move the nodes closer together. I drag a copy of the new function onto the screen from the project tree. This added a node without any inputs or outputs. I go back to the function node screen by either selecting its tab, or by double clicking on its node. Next to the inputs and outputs on nodes there are some button icons. The one on the left makes that input or output exposed to other agents. I click on that icon for the Activation input on the transform number node, and the Activation output on the switch. They have a red outline now so I can see that they are external. In the bottom right of the screen is a button that says “Save and update function instances”. I click on that to save my function and update the node on the agent screen. If I go back to the agent I can see that my function node now has an input and output. I connect the input node and output and now my program is working again. Now to finish my project, I select these three nodes, make a copy by pressing Control C or using the right click menu, then paste a copy using Control V or the menu. Finally I have to change the pins on the new nodes. On the input node I select pin A3 and on the output node I select pin 5, then I refresh the connection program. Now both LEDs blink, and each can be controlled by its potentiometer.

  • A - The input and output nodes that connect to the first LED and potentiometer.

  • B - Two copies of the Speed Controlled Blink function. Each of these nodes encapsulates a copy of the 4 nodes in the function.

  • C - Two new input and output nodes for the new LED and potentiometer. Make sure to change the pin numbers to the pins you plugged your hardware into.

View Comments (0)