This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
en:iot-open:programming_fundamentals_rtu:building_your_first_project [2018/01/12 13:58] – Agrisnik | en:iot-open:programming_fundamentals_rtu:building_your_first_project [2020/07/20 09:00] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 108: | Line 108: | ||
<figure label> | <figure label> | ||
- | {{ https:// | + | {{ https:// |
< | < | ||
</ | </ | ||
Line 119: | Line 119: | ||
</ | </ | ||
+ | The code of the example program is the following: | ||
+ | <code c> | ||
+ | // the setup function runs once when you press reset or power the board | ||
+ | void setup() { | ||
+ | // initialize digital pin LED_BUILTIN as an output. LED_BUILTIN stands for the built-in LED on the board. | ||
+ | pinMode(LED_BUILTIN, | ||
+ | } | ||
+ | // the loop function runs over and over again forever | ||
+ | void loop() { | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | delay(1000); | ||
+ | digitalWrite(LED_BUILTIN, | ||
+ | delay(1000); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | In the source code of program following things can be seen: | ||
+ | - It it defined that the LED_BUILTIN is set to be the output of the program. In this example sketch, the output periodically sends the specific signal that is in the level of the logical 1 (+5V) and 0 (0V). Sending output signal to the built-in LED, the LED is periodically turned on and off. | ||
+ | - Continuous executable function //loop()// is created that allocates 1 second (1000 ms) of time to each level of signal. It is done by pausing the execution of program. While the program is not changing the states of the inputs/ | ||
+ | - The last row indicates that the program will be paused for a 1 second also when the output level is set to be 0 V. In this way the period of LED on and off are equal. After executing this program, the program returns to the first line of the //loop()// function and the execution starts from the beginning. | ||
===== Hello World ===== | ===== Hello World ===== | ||
+ | "// | ||
+ | Here is the //Hello World// program for Arduino that outputs the text on the Serial Monitor each second: | ||
+ | <code c> | ||
+ | void setup() { | ||
+ | Serial.begin(9600); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | Serial.println(" | ||
+ | delay(1000); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Serial Monitor can be found following the path: // | ||
+ | |||
+ | In the code can be seen that the //setup()// function contains the following command: | ||
+ | <code c> | ||
+ | Serial.begin(9600); | ||
+ | </ | ||
+ | This statement opens the serial port at the initialization of the program so that the Serial Monitor can be used for outputting text or values on the screen. | ||
+ | |||
+ | For printing out text the following command is used: | ||
+ | <code c> | ||
+ | Serial.println(" | ||
+ | </ | ||
+ | |||
+ | **Check yourself** | ||
+ | |||
+ | 1. How to attach any library to a sketch? | ||
+ | |||
+ | 2. What command expressions are not usually separate by semicolon? | ||
+ | |||
+ | 3. How to establish a serial communication between devices? | ||
+ | |||
+ | 4. How does delay() command works? | ||
+ | |||
+ | *Stops LED blinking specified number of milliseconds | ||
+ | |||
+ | *Stops program execution for a specified number of seconds | ||
+ | *Stops program execution for a specified number of milliseconds | ||