-
Notifications
You must be signed in to change notification settings - Fork 27
Tutorial : Create and use functions
If you do not know how to create a new project have a look to the tutorial How to create a new project ?.
In this tutorial we will see how to define a simple function and reuse it with the Arduino Designer.
In this example we use the Arduino Uno platform and hardware components from the DFRobot Ardublock kit.
The hardware is defined as below :
The DFRduino Uno R3
platform is used, the white LED
module is connected to the digital pin 11
of the Arduino board. It is important to connect the LED to a PWM digital pin. PWM is a technique for getting an analog-like behavior from a digital output by switching it off and on very fast.
In the sketch, we use the blue and red LEDs as Status modules.
The function must be created thanks to the New
function tool available in the Functions
section of the palette. Then to edit the function definition, double click on it. A new editor opens. You can define the parameters of the function thanks to the xxx Parameter
tools available in the Functions
palette. To then reference a defined parameter in the sketch, use the Use Parameter
tool.
Then go back to the Sketch
representation and define the function parameters using the Parameter
tool.
A function can be reused just by selecting the Use
tool available in the Functions
section. This tool opens a wizard proposing all the defined functions.
Finally, click on the Upload
button from the toolbar to upload the code to the Arduino board.
The source of this example are available in : https://github.com/mbats/arduino/tree/master/examples/fr.obeo.dsl.arduino.examples.functions