Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:iot-open:programming_fundamentals_rtu:building_your_first_project [2018/01/12 13:58] Agrisniken: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://home.roboticlab.eu/_media/en/iot-open/programming_fundamentals_rtu/chooseport.png?800 |title}}+{{ https://home.roboticlab.eu/_media/en/iot-open/programming_fundamentals_rtu/example.png?600 |title}}
 <caption>The path to open the //Blink LED// example program</caption> <caption>The path to open the //Blink LED// example program</caption>
 </figure> </figure>
Line 119: Line 119:
 </figure> </figure>
  
 +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, OUTPUT);
 +}
  
 +// the loop function runs over and over again forever
 +void loop() {
 +  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
 +  delay(1000);                       // wait for a second
 +  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
 +  delay(1000);                       // wait for a second
 +}
 +</code>
 +
 +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/outputs, they remain unchanged. In this way, when the +5 V signal is sent to the LED output and the program execution is paused, the LED will continue to shine until the level of the output will be set to 0 V.
 +  - 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 =====
 +"//Hello World//" program is the simplest program, because it simply outputs the text to the screen.
 +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); //establishes the connection with the serial port
 +}
 +
 +void loop() {
 +  Serial.println("Hello World"); //prints out the line with the text
 +  delay(1000);                   //pause for 1 second
 +}
 +</code>
 +
 +Serial Monitor can be found following the path: //Tools->Serial Monitor//.
 +
 +In the code can be seen that the //setup()// function contains the following command:
 +<code c>
 +Serial.begin(9600);
 +</code>
 +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("Hello World");
 +</code>
 +
 +**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
  
en/iot-open/programming_fundamentals_rtu/building_your_first_project.1515765534.txt.gz · Last modified: 2020/07/20 09:00 (external edit)
CC Attribution-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0